You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
Add an MGLPolyline with (at least) two points around the antimeridian.
Center the polyline using mapView.setVisibleCoordinateBounds(line.overlayBounds, …) or mapView.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 for overlayBounds, it falls back to MGLMultiPoint's. That implementation goes through all points and figures out the bounding box by min/maxing 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 an MGLPolyline, 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.
The text was updated successfully, but these errors were encountered:
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.
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 an
MGLPolyline
, 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.The text was updated successfully, but these errors were encountered: