summaryrefslogtreecommitdiff
path: root/platform/ios/src/MGLMapView.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/src/MGLMapView.mm')
-rw-r--r--platform/ios/src/MGLMapView.mm27
1 files changed, 21 insertions, 6 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 8ca41b328c..92d3724b03 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -3527,18 +3527,33 @@ public:
- (CGRect)convertCoordinateBounds:(MGLCoordinateBounds)bounds toRectToView:(nullable UIView *)view
{
- if ( ! CLLocationCoordinate2DIsValid(bounds.sw) || ! CLLocationCoordinate2DIsValid(bounds.ne))
- {
- return CGRectNull;
- }
return [self convertLatLngBounds:MGLLatLngBoundsFromCoordinateBounds(bounds) toRectToView:view];
}
/// Converts a geographic bounding box to a rectangle in the view’s coordinate
/// system.
- (CGRect)convertLatLngBounds:(mbgl::LatLngBounds)bounds toRectToView:(nullable UIView *)view {
- CGRect rect = { [self convertLatLng:bounds.southwest() toPointToView:view], CGSizeZero };
- rect = MGLExtendRect(rect, [self convertLatLng:bounds.northeast() toPointToView:view]);
+ auto northwest = bounds.northwest();
+ auto northeast = bounds.northeast();
+ auto southwest = bounds.southwest();
+ auto southeast = bounds.southeast();
+
+ auto center = [self convertPoint:{ CGRectGetMidX(view.bounds), CGRectGetMidY(view.bounds) } toLatLngFromView:view];
+
+ // Extend bounds to account for the antimeridian
+ northwest.unwrapForShortestPath(center);
+ northeast.unwrapForShortestPath(center);
+ southwest.unwrapForShortestPath(center);
+ southeast.unwrapForShortestPath(center);
+
+ auto correctedLatLngBounds = mbgl::LatLngBounds::empty();
+ correctedLatLngBounds.extend(northwest);
+ correctedLatLngBounds.extend(northeast);
+ correctedLatLngBounds.extend(southwest);
+ correctedLatLngBounds.extend(southeast);
+
+ CGRect rect = { [self convertLatLng:correctedLatLngBounds.southwest() toPointToView:view], CGSizeZero };
+ rect = MGLExtendRect(rect, [self convertLatLng:correctedLatLngBounds.northeast() toPointToView:view]);
return rect;
}