TransWikia.com

Stop Leaflet event propagation?

Geographic Information Systems Asked by Muhammad on December 17, 2020

I have a feature layer and some pins on it, with mouseout, mouseover events callbacks on the feature. When the mouse is over the pin icon, that triggers mouseout event (mouseout from the feature layer). I am trying to stop event propagation but nothing works.

How can the leaflet event propagation be stopped?

None of those worked:

DomEvent.stopPropagation(e);
DomEvent.preventDefault(e);
DomEvent.stop(e);
stopPropagation(e.originalEvent);
preventDefault(e.originalEvent);
stop(e.originalEvent); 

2 Answers

Okay, finally got it figured out on stopping the propagation of events. e.g.

someReference.on("click", (evt: L.LeafletEvent) => {
    // You don't try to reference the event (evt) that is passed in

    L.DomEvent.preventDefault(evt); // Just call this
    ...
})

Answered by Elijah on December 17, 2020

If you're interested in stopping propagation for a Marker, you can just set bubblingMouseEvents to false in the options: https://leafletjs.com/reference-1.6.0.html#marker-bubblingmouseevents

Answered by Trevor Robinson on December 17, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP