Skip to content

Fix antimeridian mouse scroll wrapping #12238

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

Merged
merged 6 commits into from
Sep 19, 2022
Merged

Conversation

avpeery
Copy link
Contributor

@avpeery avpeery commented Sep 15, 2022

This change fixes a bug where scroll zooming jumps while crossing the antimeridian when using a mouse to scroll zoom or with a large trackpad scroll zoom motion on projections that wrap. When using small trackpad scroll zooms, the scroll zoom handler restarts each time. However with large trackpad scroll zooms and mouse scroll zooms, the scroll zoom handler sets an "easing" function to ease the motion of the scroll zoom. Because of this, these scroll zooms do not restart with each motion and use the easing function to guide the direction of the zooming. When crossing the antimeridian during these scroll zooms, the scroll zoom has not accounted for wrapping since it is relying on the previously set easing function and acts as if the distance to travel is across the map.

This solution forces the scroll zoom handler to "restart" by clearing the previously stored settings (which would cause the easing function to calculate a much further distance) when crossing the antimeridian,

There is one trade-off with this solution in that when using a very forceful trackpad motion directly over the antimeridian, the trackpad motion isn't smooth; however it is accurate. If it is not directly over the antimeridian or the trackpad motion isn't overly forceful, the trackpad motion is not impacted. Mouse motions are smooth in both cases.

Before (mouse scroll jumps when crossing antimeridian):

Screen.Recording.2022-09-15.at.6.15.56.PM.mov

After:

Screen.Recording.2022-09-15.at.6.31.33.PM.mov

Launch Checklist

  • briefly describe the changes in this PR
  • include before/after visuals or gifs if this PR includes visual changes
  • write tests for all new functionality
  • manually test the debug page
  • apply changelog label ('bug', 'feature', 'docs', etc) or use the label 'skip changelog'
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>Fix jumping when scrolling with mouse when crossing the antimeridian on projections that wrap.</changelog>

Sorry, something went wrong.

@avpeery avpeery changed the title fix antimeridian mouse scroll wrapping Fix antimeridian mouse scroll wrapping Sep 15, 2022
@avpeery avpeery marked this pull request as ready for review September 16, 2022 06:47
@avpeery avpeery requested a review from a team as a code owner September 16, 2022 06:47
Copy link
Contributor

@stepankuzmin stepankuzmin left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me! Unfortunately, I don't have an actual mouse at the moment to test it properly.

Copy link
Contributor

@SnailBones SnailBones left a comment

Choose a reason for hiding this comment

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

Tested with mouse and trackpad, LGTM!

@avpeery avpeery merged commit d69a49d into main Sep 19, 2022
@avpeery avpeery deleted the avpeery/mouse-antimeridan-fix branch September 19, 2022 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zoom in with the mouse wheel moves the map center if near antimeridian
3 participants