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

Fire events on cooperative gesture triggers #4464

Closed
tomhicks opened this issue Jul 29, 2024 · 2 comments · Fixed by #4470
Closed

Fire events on cooperative gesture triggers #4464

tomhicks opened this issue Jul 29, 2024 · 2 comments · Fixed by #4470

Comments

@tomhicks
Copy link
Contributor

User Story

As a developer embedding a MapLibre map with cooperative gestures, I want to receive events when the cooperative gestures are detected and triggered, so that I can put up my own UI instead of hacking the internal one.

Rationale

We want a custom cooperative gesture UI, which I have managed to get pretty much working by overriding the styles globally, but it's starting to get a bit fiddly. For instance, I need to separate the scrim from the message to be able to layer the scrim behind some UI but have the message above it. I can work around this by putting mutation observers on the DOM elements that are modified as the gestures are triggered, but that's a bit flaky.

If we were able to register for an event like "cooperativegestureblocked" or something we would be able to more easily add our own custom UI.

Impact

Makes it harder to implement custom UIs for cooperative gestures.

PR

I'm very happy to make a PR for this, if someone could just point me to the right way to get the event emitter instance into the handler (or to import a singleton).

@HarelM
Copy link
Collaborator

HarelM commented Jul 29, 2024

I'm not sure how am event will solve your problem, but the code is mainly here:
https://github.com/maplibre/maplibre-gl-js/blob/c0f1936e39528d4b9e3a91463c20cba7c3649a6b/src/ui/handler/cooperative_gestures.ts
I would consider copying the code, modify it and replacing the existing instance:

cooperativeGestures: CooperativeGesturesHandler;

@tomhicks
Copy link
Contributor Author

Ah I think what I need is this._map.fire and then some additional types or whatever to allow that to compile.

Then we should be able to do map.on("cooperativegestureprevented", handler)

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

Successfully merging a pull request may close this issue.

2 participants