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

Always wrap center coordinate to the range [-180, 180] #11448

Merged
merged 4 commits into from
Feb 2, 2022

Conversation

mpulkki-mapbox
Copy link
Contributor

@mpulkki-mapbox mpulkki-mapbox commented Jan 31, 2022

Panning the map doesn't automatically wrap the center point to the range [-180, 180]. User can move the map outside of the screen so that nothing gets rendered. This is possible as center.wrap() is invoked only during easing of the fling gesture and not at all if user pans the map without leaving any inertia.

gljs_center_wrap_bug.mp4

This PR fixes the issue by wrapping the center point in transform._translateCameraConstrained(). Additionally the pointCoordinate implementation for the globe view had to be updated to return non-wrapped coordinates to reflect the change.

Fixes the following issue #11354 which was caused by mixed usage of wrapped and unwrapped coordinates in tile coverage computations.

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 map center not being wrapped properly after a drag gesture.</changelog>

@mpulkki-mapbox mpulkki-mapbox marked this pull request as ready for review January 31, 2022 11:12
export function shortestAngle(a: number, b: number): number {
const diff = (b - a + 180) % 360 - 180;
return diff < -180 ? diff + 360 : diff;
}
Copy link
Contributor

@SnailBones SnailBones Jan 31, 2022

Choose a reason for hiding this comment

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

Why is this function in util.js rather than inlined? Will it be used in other places? Or is this for ease of unit testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Finding signed distance between two angles is a quite common and useful operation and a good candidate for having its own utility function. I couldn't find any good reasons for inlining it as the code path is not particularly hot and it's easier to test too. Would you like to see it inlined instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Those all seem like good reasons. Great work @mpulkki-mapbox!

@SnailBones SnailBones linked an issue Feb 1, 2022 that may be closed by this pull request
Copy link
Contributor

@karimnaaji karimnaaji left a comment

Choose a reason for hiding this comment

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

LGTM! Could you also make sure to update the changelog entry for that change?

@karimnaaji karimnaaji merged commit 8083265 into main Feb 2, 2022
@karimnaaji karimnaaji deleted the mpulkki-fix-center-wrap branch February 2, 2022 17:09
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.

Low fidelity appearance of the globe can remain stuck
3 participants