maplibre-gl-js
maplibre-gl-js copied to clipboard
contextmenu events not firing before scrolling/zooming "finishes"
maplibre-gl-js version: 5.3.0
browser: Firefox 136, Chromium 133
Steps to Trigger Behavior
- Add an event handler for
contextmenu:map.on('contextmenu', () => { console.log('contextmenu fired'); }; - Scroll the map using the mouse wheel
- Directly after scrolling, right click on the map
Expected Behavior
The contextmenu event should fire and contextmenu fired should be logged to the console.
Actual Behavior
Nothing. The expected behaviour only works after some time (half a second? seems to be after the render finishes?).
Can't reproduce when zooming using the controls. Seems to be related to mouse event handling.
Would be interesting if someone can reproduce this using the Contextmenu key on the Keyboard (i don't have such a key).
Looking at the code, this is by design (not sure design is the right word here, but still).
The following method is blocking the handling of other handler in the handlers list.
So there's hierarchy of handlers, and the last one is the contextmenu (BlockableMapEventHandler), so when the user scrolls using the mouse (not thought "API") this is blocked:
https://github.com/maplibre/maplibre-gl-js/blob/cc701940c07f72c70d6e370824fae03e6df57347/src/ui/handler_manager.ts#L336
In theory, one could change the following line to address this issue:
+this._add('blockableMapEvent', new BlockableMapEventHandler(map), ['scrollZoom']);
-this._add('blockableMapEvent', new BlockableMapEventHandler(map));
@HarelM I have opened a PR using the suggested fix here and the approach of adding a failing test first. I wasn't able to reproduce this in a unit test, only in an integration test. https://github.com/maplibre/maplibre-gl-js/pull/6529
If it looks OK, I can take a look at https://github.com/maplibre/maplibre-gl-js/issues/6302 and check if this makes a difference there and update tests. Happy for feedback!
Thanks @mmc1718!! I left a small comment...
Thanks for the quick response @HarelM ! I have updated the PR to address the comments