Fix antimeridian mouse scroll wrapping #12238
Merged
+26
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
mapbox-gl-js
changelog:<changelog>Fix jumping when scrolling with mouse when crossing the antimeridian on projections that wrap.</changelog>