Sunday, February 27, 2011

Bing Maps 7 API bug in MouseEventArgs.getX and getY

The new Bing Maps is a lot more lightweight, and the changes in event handling makes more sense. For example, it is now possible to detect viewchangeend event instead of using an assortment of onendpan, timers and getCenter to detect whether the view has changed.

However, I ran into the same problem mentioned here The mouse wheel and double click do not zoom at the location of the mouse. Worse still, adding a pushpin when the user clicked on the map results in the pushpin being placed too high up on the map. How much higher the pushpin is placed also depends on the browser used.

Upon investigating the MouseEventArgs.getX and getY functions, I found that they depended on getViewportX and getViewportY functions. By replacing the getViewportY function with one that uses jQuery to calculate the correct offset, I managed to get the mouse wheel, double click and pushpins to all work correctly.

var map = new Microsoft.Maps.Map($("#map")[0],


    credentials: "",

    center: new Microsoft.Maps.Location(1.35, 103.82),

    zoom: 11,

    showDashboard: false



map.getViewportY = function () {

    return $("#map").offset().top + $("#map").height() / 2;


However, it does introduce a problem whereby the dashboards navigations no longer work correctly and the view type menu displays too far down. It thus necessitates writing my own dashboard.

No comments: