maplibre-gl-js icon indicating copy to clipboard operation
maplibre-gl-js copied to clipboard

contextmenu events not firing before scrolling/zooming "finishes"

Open chrneumann opened this issue 8 months ago • 2 comments

maplibre-gl-js version: 5.3.0

browser: Firefox 136, Chromium 133

Steps to Trigger Behavior

  1. Add an event handler for contextmenu: map.on('contextmenu', () => { console.log('contextmenu fired'); };
  2. Scroll the map using the mouse wheel
  3. 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?).

chrneumann avatar Mar 27 '25 11:03 chrneumann

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).

chrneumann avatar Mar 27 '25 11:03 chrneumann

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 avatar Apr 14 '25 20:04 HarelM

@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!

mmc1718 avatar Oct 10 '25 12:10 mmc1718

Thanks @mmc1718!! I left a small comment...

HarelM avatar Oct 10 '25 13:10 HarelM

Thanks for the quick response @HarelM ! I have updated the PR to address the comments

mmc1718 avatar Oct 10 '25 17:10 mmc1718