Skip to content
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

Stop event propagation #45

Closed
glops opened this issue Aug 28, 2023 · 3 comments · Fixed by #49
Closed

Stop event propagation #45

glops opened this issue Aug 28, 2023 · 3 comments · Fixed by #49

Comments

@glops
Copy link

glops commented Aug 28, 2023

Hello

First, thanks for this great library !

I have multiple layers placed on top of each other. I would like to stop event propagation.

Here is a demo of the problem : svelte-mapping-multi-layer-event

It draws a red square on top of a green square. When you click at the intersection of both squares, both events are triggered.

image

I have tried several methods like :

    event.stopImmediatePropagation()
    event.stopPropagation()
    event.preventDefault()
    event.detail.event.originalEvent.stopImmediatePropagation()
    event.detail.event.originalEvent.stopPropagation()

But nothing works.
Do you know how to achieve this ?

In svelte-leaflet, there is an option for this :

options={{ bubblingMouseEvents: false }}
@dimfeld
Copy link
Owner

dimfeld commented Aug 29, 2023

Yeah, it's very different with MapLibre/Mapbox because they're using WebGL, so all the normal DOM methods don't apply. One potential technique is to use a click handler for all the layers that uses map.queryRenderedFeatures to find the topmost layer from all the layers, as detailed in this Stackoverflow answer.

This feels potentially useful as something to support doing within this library itself, but I would have to think about the best way to manage the information about which layers to query. But in the meantime, I hope this helps!

@dimfeld
Copy link
Owner

dimfeld commented Aug 31, 2023

I just published version 0.3.4, which lets you set eventsIfTopMost on a layer to get the behavior you're looking for. There's an example on the website. Thanks for the suggestion!

@glops
Copy link
Author

glops commented Sep 1, 2023

Thank you it works great !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants