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

cheesybiscuits thomaschristian at gmail.com
Thu May 31 14:52:42 PDT 2012


I'm writing a feature that allows a user to drag a JQuery draggable image on
to an OpenLayers map, then when they 'drop' it (release the mouse) I create
a feature at that location through my GeoServer's WFS-T interface.

So far I have been getting the mouse's lat/lon position by querying the
map's MousePosition control's lastXy property and it seems to be giving an
accurate pixel location, which I of course convert to a lat/lon object.

This was all great until I tested in IE(8 & 9)... It seems like when I drag
the draggable element over the map the mouse stops firing mousemove events,
so when the mouse is released the MousePosition control has the wrong
position.

I realise I could use an OpenLayers feature which is draggable, instead of a
JQuery draggable element, but one of my requirements is that the draggable
object originates outside the map. Also I'm sure I could come up with some
setTimeout hack in the hope that the mouse position is updated in time for
my drop handler, but this would never get past code review.

What I need is a way of actively querying the mouse's position over the map
(in an OpenLayers.Pixel object), whenever I want it. However I have only
ever seen examples or read discussions that rely on a click event to get the
current position, and my users won't be clicking on the map (just releasing
a mouse button, or maybe lifting their finger off a touch screen).

If anyone has a suggestion on how to get an accurate OpenLayers.Pixel object
without requiring a click event I would be very grateful.

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


More information about the Users mailing list