-
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
Disabling and enabling the box zoom interaction messes it up #2237
Comments
I believe the problem here is that the current implementation of interaction handlers depends on initialization order. When the handlers are initially enabled in the order defined in This could be adressed by making Personally I would say that this is a quite serious issue as it more or less means that disabling and enabling of interactions will yield unexpected results for a user of the API. Also worth mentioning that this is only relevant for interactions that base their behaviour upon the active state of others. |
... another possible solution is actually to let disabled interaction handlers keep their event listeners registered, but ignore them. That way the order of the initially registered event listeners would remain intact. |
@lucaswoj @jfirebaugh Any opinions on my last suggested option of letting listeners persist for disabled handlers but making them noops? Feels a bit like a workaround of the real problem, but at the same time, implementing arbitrary handler initialization order may be complicated and create more inter-handler-dependencies. @mourner Any good experiences from how leaflet does it here? |
@averas in Leaflet, I don't recall any situations where interactions would depend on the order they were enabled. We need to figure out the core issue here. Why is it order-dependent in the first place? |
In this particular case (there may be more), there is a check in
This implicitly requires that the |
Oh, I see. Yeah, that's a tricky issue. I think we should find another way to bail out of a handler, not using |
I can confirm that this bug is still present in |
My workaround for this is to disable both the dragPan and the doubleClickZoom, and then re-enable them all in the following order: boxZoom, doubleClickZoom, dragPan. I'm not sure if the re-enabling doubleClickZoom is necessary, but that is the order they all started up in originally. |
AFAIK, the 'best practice' for adding / removing event listeners is to remove listeners on DOM-teardowns (when removing a DOM element), but otherwise persist the listener. In addition, event listeners can't be removed while they are active (this affects touch track and mouse drag listeners), meaning that some listeners need a different disable mechanism anyway. Given the low amount of listeners invoked by mapbox-gl, I don't think any noticeable memory or performance issues will appear if they persist either. All in all, I think persisting listeners would be both simpler to implement and give more control of handling input events. @mourner what are your thoughts on this? |
@mourner Thanks for the confirmation, didn't see that issue. I'll sketch out a more detailed proposal and tie all this together in a summarized ticket when I have time. On top of my head (let me know if you think this is the wrong direction): If we want to support a few of the 'advanced' touch guestures that are supported in mapbox-gl-native, we'll need some kind of 'gesture recognizer' logic (similar to what hammer.js and a few other gesture libs I've checked are using). This recognizer should be responsible for delegating events to the correct handler, instead the current pattern where each handler have to check and set the state of other handlers on input. This recognizer pattern would represent a major rewrite of the existing logic, so I'd prefer to first focus on fixing the most critical current issues (number one would be to retain listeners, then iron out the edge cases that have already been identified). |
Discovered this while working on #2173
mapbox-gl-js 0.15.0:
Steps to Trigger Behavior
map.on("load", ...)
map.boxZoom.disable();
map.boxZoom.enable();
Demonstration at http://codepen.io/anon/pen/LNNqrP
Expected Behavior
That it works as before disable/enable.
Actual Behavior
Map gets stuck dragging right after the box zoom, as if the mouse button is down even though it is not.
This may be related to OSX and have a similar root cause of #1888
The text was updated successfully, but these errors were encountered: