summaryrefslogtreecommitdiff
path: root/platform/macos/src/MGLMapView.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/macos/src/MGLMapView.mm')
-rw-r--r--platform/macos/src/MGLMapView.mm26
1 files changed, 21 insertions, 5 deletions
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 3c1fe18499..92ba89f72d 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -2820,17 +2820,33 @@ public:
}
- (NSRect)convertCoordinateBounds:(MGLCoordinateBounds)bounds toRectToView:(nullable NSView *)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.
- (NSRect)convertLatLngBounds:(mbgl::LatLngBounds)bounds toRectToView:(nullable NSView *)view {
- NSRect rect = { [self convertLatLng:bounds.southwest() toPointToView:view], NSZeroSize };
- 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:{ NSMidX(view.bounds), NSMidY(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);
+
+ NSRect rect = { [self convertLatLng:correctedLatLngBounds.southwest() toPointToView:view], CGSizeZero };
+ rect = MGLExtendRect(rect, [self convertLatLng:correctedLatLngBounds.northeast() toPointToView:view]);
return rect;
}