Wednesday, 24 June 2015

javascript - How to display mouse position as tooltip in OpenLayers-2?


I want map coordinates as mouse over effect in OpenLayers. I am using the following code. However it is showing pixel coordinates:


    map.events.register("mousemove", map, function(e) {      
var position = e.map.x + e.xy.y;
OpenLayers.Util.getElement("tooltip").innerHTML = position

});

Answer



you can convert pixels to lat/long with the help of getLonLatFromPixel() function.


See also openlayers FAQ.


No comments:

Post a Comment