-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[core] Avoid wrapping longitude values of exactly 180 and 360 (#12797) #13006
Conversation
@ansis I was told you may have some knowledge on this area of the codebase. Does this change look reasonable as a solution or is this likely to have unexpected adverse effects elsewhere? cc @mollymerp |
/cc @captainbarbosa for potential impact on your recent iOS change. |
This is supposed to fix the conversion from java bounds to native bounds, right? I'm not sure that Let's say you have these java bounds that cover most of the width of the world: I think I haven't run this to confirm I'm not reading this wrong, but why would bounds want to use the shortest path between two locations? It looks like this was added in https://github.com/mapbox/mapbox-gl-native/pull/11807/files |
@ansis #11807 was added to close #11733 which is a popular scenario where users would like to position a camera based on bounds that cross the antimeridian, so values passed to JNI are that lon east < lon west. We need to unwrap them, otherwise, as you pointed out, the |
@LukasPaczos It looks like the example from my previous comment produces unexpected results (thanks @ryanhamley for running this).
In the resulting map the east side is -170 and the west is 170: My suggestions:
More open questions (that could already be settled by the core implementation):
Relatedly, a while back John made a pretty convincing case for eliminating bounds and using geojson instead of the north/east/south/west format: mapbox/mapbox-gl-js#2112 (comment) |
This is what this PR was originally intended to fix (#12797). According to that bug report, |
This documentation describes the expected wrapping behavior on iOS. Note that it differs from MapKit’s behavior, which tries to guess at the developer’s intent while constraining the longitude to ±180°. It’s expected that mapbox-gl-native/platform/darwin/src/MGLGeometry_Private.h Lines 55 to 58 in f4ffcaa
For what it’s worth, MapKit largely eschews the concept of a bounding box in favor of a “region”, which consists of a center point and span (vertical and horizontal degrees spanned by the region). This center-centric approach is suitable for transitions between Mercator and non-Mercator projections, as when switching between standard and satellite modes in Apple Maps. It also neatly avoids any problems spanning the antimeridian. |
We're planning on removing forced wrapping of longitude values in the upcoming Android semver major release (see #13149) which will enable us to pass values straight to core without any manipulation. This, I believe, will establish parity with the iOS implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merging this as a temporary fix seems ok!
Long term fix is #13006 (comment) to address #13186.
This will not need to be undone after those changes because I think this change makes sense for the expected uses of the method as well.
f806be2
to
fbac065
Compare
Fixes #12797
The thinking here is that 180 and 360 are special values that do not need to be wrapped. In the case of #12797
unwrapForShortestPath
was causing a bug because-180
was being converted to180
and confining the viewport to the antimeridian when it should have been possible to scroll horizontally around the world.TODO:
add test(s)- not needed for this. tests for generalized bounding box behavior are in progress at [Core] Add tests for bounding boxes that cross the antimeridian #13087