Closed RyanEwen closed 12 years ago
You can stop the map from dragging by calling preventDefault()
on "mousedown" events.
Sorry, I think you misunderstood.
I don't want to prevent map drags. The issue is that when the map is dragged it triggers a 'click' event when dragging is ended. I can't differentiate between this click event and an actual click (without drag) event.
In my specific case I would like to deselect an item (something I've added on my own custom layer) when the map is clicked. However, simply dragging the map causes items to become deselected as well, which isn't desired.
Ah, sorry! Yeah, I think that in order to prevent them you can either listen for "click" events before adding the drag handler (so that your listener gets called first and you can stopPropagation()
) or listen for "mouseup" events and preventDefault()
on those.
Thanks for the suggestions. I tried both but had no luck. I think it's because if I stopPropagation() on a click, it's not doing anything aside from stopping clicks from reaching the map's container (which I am already doing).
When I do preventDefault() on mouseup then it prevents the legit map clicks.
Sad face. Oh well.
Okay, how about this technique:
var downtime = +new Date()
)var uptime = +new Date()
)var delta = uptime - downtime
), and if it's >= some threshold (say, 250ms), preventDefault()
.I used this on Surging Seas to prevent errant clicks on place labels, and it works pretty well.
Hi there,
I would like to listen for click events on my map but I am unsure as of how to prevent the map move event from triggering a click event once a map drag has finished.
Is there a way to do that?