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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...