0
votes

I've created an app where I use several custom HTML pushpins. Each one of these pushpins has a click event that will call setView on the map to center the map on the selected pin. This works perfectly in all browsers except for Firefox (testing version 22.0).

In Firefox, after the setView animation completes and the map is centered on the pushpin, the pushpin is then offset horizontally, vertically or both by a certain amount of pixels. The amount seems to correspond with amount of pixels the map has moved. If you then drag the map manually with the mouse, upon releasing the mouse button, the pushpin snaps back to its proper place. I've checked the top and left position values of the MapPushpinBase anchor tag in compared it with other browsers and the values differ.

Unfortunately, I cannot post a live example because the product has not yet been publicly released. But see below for the code I'm using.

this.clickHandlers.push(Microsoft.Maps.Events.addHandler(node, 'click', function (e) {
    var element = $(e.target._htmlContent);
    self.nodeHitboxHandler(element);
}));

Within the nodeHitboxHandler function, the only piece of Bing Map code is this:

this.map.setView({
    center: new Microsoft.Maps.Location(panStart.latitude, panStart.longitude),
    zoom: this.zoom,
    mapTypeId: Microsoft.Maps.MapTypeId[self.mapTypeId]
});

Thanks in advance for any help.

UPDATE:

In order to make things clearer, I've created a simple example that demonstrates the problem. You can see it here: http://ginof.com/tests/bing/

In Firefox, try clicking on the different pushpins and watch the behaviour of the pushpin you've just clicked on after the map finishes panning to its new location. The map works fine in all browsers except Firefox.

Here's the complete JavaScript code for this example:

$(document).ready(function () {
    var map = null,
        initialCoordinates = {latitude: 40.71435, longitude: -74.00597},
        initialPoint = new Microsoft.Maps.Location(initialCoordinates.latitude, initialCoordinates.longitude),
        range = {
            top: 3,
            right: 5,
            bottom: 0.01,
            left: 5
        },
        mapOptions = {
            credentials:"BING-MAPS-API-KEY",
            disableKeyboardInput: true,
            disableZooming: true,
            enableClickableLogo: false,
            enableSearchLogo: false,
            showBreadcrumb: false,
            showDashboard: false,
            showMapTypeSelector: false,
            showScalebar: false,
            inertiaIntensity: 0.5,
            mapTypeId: Microsoft.Maps.MapTypeId.birdseye,
            labelOverlay: Microsoft.Maps.LabelOverlay.hidden,
            center: initialPoint,
            zoom: 14
        };

    function GetMap() {
        // Initialize the map
        map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), mapOptions);

        // Create nodes
        map.entities.clear();
        var pushpinOptions,
            pushpin,
            nodeCoordinates;

        for (var i = 0; i < 5; i++) {
            pushpinOptions = {width: null, height: null, htmlContent: '<div id="node' + i + '" class="node">' + i + '. Custom HTML</div>'}; 
            nodeCoordinates = {latitude: initialCoordinates.latitude + i * 0.005, longitude: initialCoordinates.longitude + i * 0.005};
            pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(nodeCoordinates.latitude, nodeCoordinates.longitude), pushpinOptions);
            pushpinClick = Microsoft.Maps.Events.addHandler(pushpin, 'click',
                (function () {
                    var nodeId = i,
                        homeCoordinates = nodeCoordinates;
                    return function () {
                        console.log("node " + nodeId + " clicked.");
                        map.setView({center: new Microsoft.Maps.Location(homeCoordinates.latitude, homeCoordinates.longitude)});
                    }
                })()
            );
            map.entities.push(pushpin);
        }
    }

    GetMap();
});

Thanks again for any help.

1

1 Answers

0
votes

This is a known issue which I was able to reproduce an has been escalated to the development team. Note that the Bing Maps forums are the best place to report these types of issues. You can find a similar thread on this topic here: http://social.msdn.microsoft.com/Forums/en-US/f77e6a80-2e0f-44c3-81cc-edb4c2327016/custom-html-pushpins-in-firefox-not-positioned-correctly