-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider stopPropagation on Marker click when draggable is true #9624
Comments
Hmm, it shouldn't be possible to have a drag of zero pixels that triggers a click. The marker's The |
Yes! The map itself has a clickTolerance (i.e., drag threshold, default It would be great to add similar tolerances to the markers... do not drag and do not cancel events if movement is less than click tolerance. Questions:
PS: I also made a fiddle to illustrate this before I realized this issue existed already https://jsfiddle.net/cchudzicki/q0bg7r18/2/ |
@ChristopherChudzicki is that the same issue as this ticket? I'm not asking for a Marker drag tolerance, I still want 1px drags to work, just asking that a map click is not triggered for small drags or for 0 pixel drags (ie. marker clicks) where draggable is true. I found it was easy to workaround this as noted above. The reason why this was a problem for me is the UI allows the marker to be set by clicking on the map, or dragging the marker, but due to this issue small drags triggered the map click and caused the marker to jump a few pixels off where the user expects it to be. |
@andrewharvey Fair question, maybe I will post it as a separate ticket. I do think it is related because as @ryanhamley mentioned:
Consequently, tiny marker drags (below map drag threshold) fire click events that originate from the map, not from the marker. Which means they cannot be cancelled by marker event listens (stopPropagation, as you mention). Edit: Although related, I do think these issues could be addressed
|
Strange I was able to to stop the map click event for tiny drags on the marker with marker.getElement().addEventListener('click', function (e) {
e.stopPropagation();
}) |
@andrewharvey In both firefox and chrome, I see consecutive |
Oh sorry you're right, I was testing this by just clicking on the marker (0px drag) which without the stopPropagation was triggering a map click, so seems this workaround is only a partial workaround. |
@ChristopherChudzicki I think you're correct in diagnosing these are two separate but related issues. If you're interested in opening a ticket for the click tolerance issue, that would be great. We'd also welcome a PR for either or both issues if you're interested.
I would vote for them having the same tolerance as the map by default and perhaps allow that to be configurable on the markers. |
mapbox-gl-js version: 1.9.1
browser: any
playground at https://jsfiddle.net/g39b5n2c/
When a Marker is draggable, dragging the Marker by a few pixels or by zero pixels causes a map click event to fire (map click doesn't fire when dragging the marker by a larger distance).
While for static markers without any interaction, I think it's a reasonable default to let the click flow down to the map and let the developer choose to stop this when they like with
The question is when draggable is set, should we automatically stopPropagation on click to avoid a small drag also triggering a map click event, or should we leave as is and leave this to the developer?
The text was updated successfully, but these errors were encountered: