mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.04k stars 2.21k forks source link

Possability to change which buttons execute which handlers #10132

Open MaxGeldner opened 3 years ago

MaxGeldner commented 3 years ago

Motivation

Some applications may use default buttons of Mapbox for other purposes. For example, an application could have an action on clicking the left mouse button and dragging on the map. In MapBox's default, this would trigger a panning action (if DragPanHandler is enabled). Another use case: An application could have a context menu when clicking on the map. To be sure, that the user doen't modify the map when clicking the right mouse button and accidentely dragging the mouse a bit, I would like to move the DragRotate's default buttons from the right mouse button to e.g. the middle mouse button.

Design

Maybe there could be options when instanitating the handlers or the map, that assign the buttons to the handlers. E.g.: You could modify that button x can start the handler y. With that you could e.g. remap the DragRotateHandler from "Right Mouse Button + Drag" to "Middle Mouse Button + Drag", if you change the button value in the options for the respective handler.

Of course developers can create interferring mouse button actions with that (two handlers react to the same button). This must be handled in some way or must be up to the developer to resolve.

Mock-Up

Example for mapping mouse buttons to a handler.

map.dragRotate.enable({
    activateWith: <0/1/2/3/4>  // Button number from MouseEvent.button
});
ShareQiu1994 commented 3 years ago

Hello, have you solved this problem ?

donmccurdy commented 1 year ago

I'm interested in this feature as well. It may be helpful to allow multiple buttons to be mapped to the same action – for example, allowing DragPanHandler to be driven by either of the left or middle mouse buttons:

map.dragRotate.enable({
    activateWith: [0, 1] // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
});

Would a pull request for this feature addition be welcome?