[OpenLayers-Users] How to get mouse position to Lat / Lon for SPERICAL Mercator

brancusi roger.moffatt at gmail.com
Fri Feb 6 11:44:20 EST 2009


Hiya

I'm building a new site using openlayers mapping for the first time (nice
job BTW) and was using;

var lonlat = map.getLonLatFromViewPortPx(evt.xy);

To turn the mouse position over the map into a latitude and longitude that I
would then do other things with in my user interface.

I've decided that a speherical mercator map looks better for my purposes,
and have followed the example here;

http://openlayers.org/dev/examples/spherical-mercator.html

I now have the map I want - but getLonLatFromViewPortPx is now returning
ridiculous values. I noted a warning about setcenter now using metres rather
than lat/lon when using this projection, so I'm guessing that the values I'm
getting back are now also in metres rather than lat/lon and given 0,0 seems
to be the center of the map, I think this may be the case.

My question is - is there a built in function in openlayers that will easily
allow me to convert the lonlat returned from the get from viewport function
back into lat/lon. I've tried playing with the forwardMercator and
inverseMercator functions but am not really sure what I'm doing even after
reading the docs so I'd appreciate it if a regular user could point me in
the right direction.

Or, put another way, how do I get the lat/lon from the current mouse
position when using spherical mercator projections?

Kind Regards
Roger


-- 
View this message in context: http://n2.nabble.com/How-to-get-mouse-position-to-Lat---Lon-for-SPERICAL-Mercator-tp2285117p2285117.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list