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
Always fire DOM event on the map too #3307
Conversation
I'm thinking about something else. As far as I understand, with the old API, as we were listening DOM events both on the vectors or marker and on the map, we were able to use the Also, I wonder if a better approach is not to extend the propagate API to always also propagate to the map. (Breakfast time. After that I'll try to add more unit tests to cover the |
@mourner I think I need your thoughts before going forward :) |
Haven't thought about this closely yet, will do :) |
@mourner this last commit makes all tests happy, but I feel like workarounding the issue, so I think a more global (expert) view is still needed :) |
In this branch don't work popup |
Yes! Because But clearly this means that this branch is work in progress. ;) |
I'm kinda lost here, need to revisit and rethink how events and propagation work to have some input in this... |
@yohanboniface as an alternative, can you please check #3450 and see if it's a good approach for this case? This way we explicitly bubble up all layer events to map. There should be the same problem with popups though. |
Note to self: create a webpage inside |
@IvanSanchez added :)
|
@mourner I'm travelling in Italy right now, so not really connected and not really behind my computer, but I will have a look for sure. As first thoughts, this option sounds really interesting, but I do think we still should support bubbling events from features (polygon, marker...) to map, and being able to stop them when we do not want this bubbling. |
So the problem with popups is that the order of the events is:
I'll spend some time trying to figure out how to fix this order into preclick-preclick-click-click. |
Good catch :) |
What I don't like in the code changes is that there's now We should look for a way to handle the issue more gracefully. |
This needs a sprint in Trondheim for sure! ;) cc @IvanSanchez (/me at SotM France for three days right now) |
@mourner, tested with addEventParent/removeEventParent: seems much more cleaner. Not sure about the perfs, though, as we are adding the map in the hash of every single Layer instance. What do you think?
I agree that, as it is, it's hacky. However, I think that if we take care of propagating events (which I think we should) we should also have of a way to stop them, nope? |
You're probably right about performance, but I need to recheck this.
Sounds good. |
@mourner Done :) |
@yohanboniface lets wait, I'm still not sure about the approach and have a feeling that we may regret merging this too hastily. |
OK :) |
I've not reached a nice solution when tried (but maybe it was just too much waves ;) ), after fixing the canvas issue. I'll make a new shot just after nomnom :) |
4b843b9
to
93742a5
Compare
In the case of canvas path, we can't add the canvas element itself as an interactiveTarget, given that it's big like the path bbox, and thus would make all this bbox target of events (so also clicking outside of the path itself, the layer would fire click event, for example)
Popup where binded by the LayerGroup, which was not finring the click event, because not propagated from the layers
93742a5
to
fd1b945
Compare
Ah what the hell! |
Always fire DOM event on the map too
Clicking on a leaflet map now fires click event on all layers and the base map. See: rstudio/leaflet#561 Leaflet/Leaflet#5313 Leaflet/Leaflet#3307
Since the new event delegation API, when we add a listener on the map, for example on "mouseover", this listener is not called when the event is targeted by a layer (Polygon, Marker…).
What I understand, is that with the old API, the event was listened both on each layer and on the map. With the new API, it's listened only on the map (which is nice) and then forwarded to the original target, but only to this target.
So here is a suggestion to fix that.
Thanks for reviewing :)