diff options
Diffstat (limited to 'platform/ios/src')
-rw-r--r-- | platform/ios/src/MGLMapView.h | 10 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 27 |
2 files changed, 29 insertions, 8 deletions
diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 20bfeeef39..02d146edcb 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -1118,8 +1118,9 @@ MGL_EXPORT IB_DESIGNABLE Converts a rectangle in the given view’s coordinate system to a geographic bounding box. - If a longitude is less than −180 degrees or greater than 180 degrees, the - bounding box straddles the antimeridian or international date line. + If the returned coordinate bounds contains a longitude is less than −180 degrees + or greater than 180 degrees, the bounding box straddles the antimeridian or + international date line. @param rect The rectangle to convert. @param view The view in whose coordinate system the rectangle is expressed. @@ -1130,6 +1131,11 @@ MGL_EXPORT IB_DESIGNABLE /** Converts a geographic bounding box to a rectangle in the given view’s coordinate system. + + To bring both sides of the antimeridian or international date line into view, + specify some longitudes less than −180 degrees or greater than 180 degrees. For + example, to show both Tokyo and San Francisco simultaneously, you could set the + visible bounds to extend from (35.68476, −220.24257) to (37.78428, −122.41310). @param bounds The geographic bounding box to convert. @param view The view in whose coordinate system the returned rectangle should 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; } |