Closed invliD closed 6 years ago
Hi, @invliD. Thank you for using Mapbox. Please refer to the documentation to learn how to use coordinates that straddle the antimeridian.
I know how I could achieve this myself. This issue is about the unexpected/broken behavior of overlayBounds
. It doesn’t even return a valid bounding box for any line that crosses the antimeridian.
Hi, @invliD. Thank you for the follow up and clarification. I am reopening this ticket.
The fix is to apply a solution similar to #11265 in the overlayBounds
property’s implementation.
Platform: iOS Mapbox SDK version: 3.7.5
Steps to trigger behavior
MGLPolyline
with (at least) two points around the antimeridian.mapView.setVisibleCoordinateBounds(line.overlayBounds, …)
ormapView.showAnnotations([line], …)
.Expected behavior
The map is centered around the line with its entire length in view
Actual behavior
The map shows as much of the world as possible with the current aspect ratio, splitting the line in two. See screenshot of a geodesic line from San Francisco to Shanghai:
Additional information
MGLPolyline
does not have its own implementation foroverlayBounds
, it falls back toMGLMultiPoint
's. That implementation goes through all points and figures out the bounding box bymin
/max
ing the next point's lat/long with the current bounds. This is not an unreasonable implementation as multiple points don't have any clear structure to them. It is, however, debatable whether the bounds of (0,179) and (0,-179) should actually be longitudes 179 to 181 instead of -179 to 179. In anMGLPolyline
, points actually have a structure, so I claim this behavior is definitely unexpected and unwanted most of the time.An additional problem in the current implementation of
overlayBounds
is the fact that it returns an "empty" bounding box if a point is "invalid" (e.g. abs(longitude) > 180). Since using longitudes > 180 or < -180 is the mechanism to render lines across the antimeridian, all such lines will produce an incorrect bounding box.