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

Enable Multi-MouseButton Support for dragPan #5354

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gottesman
Copy link

This PR enhances the functionality of dragPan in MapLibre GL JS, addressing feature request #5341.
It introduces the ability to configure one or multiple mouse buttons for the dragPan interaction using the MouseEvent.button property.

Previously, dragPan was limited to left mouse button, restricting user interaction and personalization. This improvement provides greater flexibility for users who want to customize the drag behavior of the map.

Examples

1. Configuring on Map Initialization:

const map = maplibregl.Map({
    container: 'map',
    dragPan: {
        buttons: [0,1]  // Enable left button (0) and middle button (1)
    }
});

2. Updating on DragPan Enable:

map.dragPan.enable({
    buttons: [1]  // Enable only middle button (1)
})

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Post benchmark scores.
  • Add an entry to CHANGELOG.md under the ## main section.

Copy link

codecov bot commented Jan 14, 2025

Codecov Report

Attention: Patch coverage is 86.11111% with 5 lines in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (f1d58f2) to head (921a48c).
Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
src/ui/handler/drag_handler.ts 62.50% 3 Missing ⚠️
src/ui/handler/drag_move_state_manager.ts 91.66% 1 Missing ⚠️
src/ui/handler/mouse.ts 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5354      +/-   ##
==========================================
- Coverage   91.84%   91.83%   -0.02%     
==========================================
  Files         282      282              
  Lines       38908    38930      +22     
  Branches     6827     6831       +4     
==========================================
+ Hits        35735    35750      +15     
- Misses       3046     3052       +6     
- Partials      127      128       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HarelM
Copy link
Collaborator

HarelM commented Jan 15, 2025

How will this behave when rotating with right click (default behavior) and setting drag pan to right click?

src/ui/handler_inertia.ts Outdated Show resolved Hide resolved
@@ -58,7 +62,7 @@ export class MouseMoveStateManager implements DragMoveStateManager<MouseEvent> {
}

isValidStartEvent(e: MouseEvent) {
return this._correctEvent(e);
return this._correctEvent(e, this._buttons);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing buttons it might be better to pass a predicate to override the default one - what happens if someone wants to have right click with control button for panning?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to point that out! I've tried setting the right click for panning and it looks like if dragRotate is enabled it will not pan the map. So it is safe for now?.
I would gladly accept any help with a better approach since I'm not good with typescript and have not much experience in large projects in general.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_correctEvent is basically what you want to override.
I would try and find a way to pass it down instead if adding a buttons parameter and pass that down...

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 this pull request may close these issues.

2 participants