-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ios, macos] Document setting visible coordinates that cross antimeridian #9804
Conversation
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.
I think it would be best if we fix this issue in mbgl so that the Android and macOS SDKs also benefit from the fix. mbgl already allows features and shape annotations to straddle the antimeridian by specifying vertices with longitudes beyond ±180°. Can you investigate how that works and adapt Transform to do likewise?
platform/ios/src/MGLMapView.mm
Outdated
|
||
mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngs(latLngs, padding); | ||
|
||
if (boundariesCrossDateTime) { |
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.
This code base calls it the “antimeridian”, not the “date time”.
|
||
@return A coordinate at given fraction. */ | ||
// Ported from http://www.movable-type.co.uk/scripts/latlong.html | ||
NS_INLINE CLLocationCoordinate2D MGLCLCoordinateAtFraction(CLLocationCoordinate2D origin, CLLocationCoordinate2D destination, double fraction) { |
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.
This is a lot of code to inline. Move the body of the function to MGLGeometry.mm.
Actually, it looks like the method affected by this PR uses |
This seems like good candidate for testing; perhaps in |
a01bddc
to
f76cf3a
Compare
@1ec5 I changed the implementation to follow this https://github.com/mapbox/mapbox-gl-native/blob/release-ios-v3.6.0-android-v5.1.0/platform/darwin/src/MGLPolyline.h#L36 that led me to avoid adding new functions. |
platform/ios/src/MGLMapView.mm
Outdated
@@ -2667,6 +2667,11 @@ - (void)_setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count | |||
{ | |||
latLngs.push_back({coordinates[i].latitude, coordinates[i].longitude}); | |||
} | |||
|
|||
if (count == 4 && coordinates[1].longitude > 0 && coordinates[3].longitude < 0) { |
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.
This public method is intended to work for an arbitrary number of coordinates.
platform/ios/src/MGLMapView.mm
Outdated
@@ -2707,6 +2712,19 @@ - (void)_setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count | |||
[self didChangeValueForKey:@"visibleCoordinateBounds"]; | |||
} | |||
|
|||
- (std::vector<mbgl::LatLng>)normalizeCoordinatesForAntimeridianSW:(CLLocationCoordinate2D)sw ne:(CLLocationCoordinate2D)ne | |||
{ | |||
CLLocationDegrees longitude = (180 + (180 - fabs(sw.longitude))) * -1; |
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.
If I’m not mistaken, the mbgl::LatLngBounds
class can handle spanning the antimeridian – that’s how the existing shape annotation functionality is able to handle the antimeridian gracefully. See the mbgl::LatLngBounds::extend()
and mbgl::LatLng::unwrapForShortestPath()
methods in particular.
@1ec5 Giving a second thought I'm thinking the best solution for this is keep the consistency across our API by adding the proper documentation to /cc @boundsj |
I’m not sure I follow. That documentation states that MGLPolyline correctly handles straddling the antimeridian on the map as long as you specify some coordinates beyond ±180° longitude. #9731 is about |
What I mean is if devs also set |
Oh, I see what you mean. If setting a coordinate bounds that goes beyond ±180° already works, then that’s great. The remaining issue is whether the developer should get the same behavior by setting a “backwards” coordinate bounds in which |
f76cf3a
to
3997c68
Compare
3997c68
to
ae76552
Compare
I added the documentation comments to clarify how to use |
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.
platform/ios/src/MGLMapView.h
Outdated
@@ -668,12 +668,24 @@ MGL_EXPORT IB_DESIGNABLE | |||
Changing the value of this property updates the receiver immediately. If you | |||
want to animate the change, call `-setVisibleCoordinateBounds:animated:` | |||
instead. | |||
|
|||
To make the visible bounds go across the antimeridian or international date line, | |||
specify some longitudes less than −180 degrees or greater than 180 degrees. |
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.
This documentation is for a getter, not a setter, so it should talk about what it means to see a longitude beyond ±180°:
If a longitude is less than −180 degrees or greater than 180 degrees, the visible bounds straddles the antimeridian or international date line.
ae76552
to
773b145
Compare
Adds documentation to clarify how to use coordinate bounds that cross the anti-meridian.