diff options
author | Nadia Barbosa <nadiabarbosa@me.com> | 2018-08-28 08:52:27 -0700 |
---|---|---|
committer | Nadia Barbosa <captainbarbosa@users.noreply.github.com> | 2018-09-04 18:57:18 -0700 |
commit | 7017ac512e96415d6a6c18512e320197a10ca83f (patch) | |
tree | e400a53a1bc5f33edb1c0a641a61c133e51ac787 /platform/macos/src | |
parent | c9803e30408cf866c1743baefcd3135f5538f9d2 (diff) | |
download | qtlocation-mapboxgl-7017ac512e96415d6a6c18512e320197a10ca83f.tar.gz |
[ios, macos] Allow -convertCoordinateBounds to span antimeridian
Diffstat (limited to 'platform/macos/src')
-rw-r--r-- | platform/macos/src/MGLMapView.h | 5 | ||||
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 26 |
2 files changed, 26 insertions, 5 deletions
diff --git a/platform/macos/src/MGLMapView.h b/platform/macos/src/MGLMapView.h index 305a1348e4..ddb5747109 100644 --- a/platform/macos/src/MGLMapView.h +++ b/platform/macos/src/MGLMapView.h @@ -1088,6 +1088,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/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; } |