[OpenLayers-Users] Get mouse position over map *without* a click event

cheesybiscuits thomaschristian at gmail.com
Mon Jun 4 09:55:10 PDT 2012


So I solved this problem but not in quite the way I wanted. It seems it's
simply not possible to get the current mouse position from the browser
without it being passed with an event, so there must always be either a
click, mousedown, mouseup, mousemove etc before you can query the mouse X
and Y.

The OpenLayers.Events class has a function called getMousePosition which
requires a mouse event as its sole argument. As I'm using JQuery draggable /
droppable functionality the drop function is passed a mouse event, so I pass
this to the getMousePosition function and get an accurate Pixel location,
which then gives an accurate Lat / Lon (I'm very happy about this as I would
have been in a real jam if it didn't).

>From my testing across a number of browsers this location is always up to
date, even though the MousePosition control's text might not yet have been
updated.

--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Get-mouse-position-over-map-without-a-click-event-tp4978414p4979036.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list