diff --git a/platform/darwin/src/MGLGeometry_Private.h b/platform/darwin/src/MGLGeometry_Private.h index 22d260625f4..c363519ea05 100644 --- a/platform/darwin/src/MGLGeometry_Private.h +++ b/platform/darwin/src/MGLGeometry_Private.h @@ -34,14 +34,12 @@ NS_INLINE mbgl::LatLngBounds MGLLatLngBoundsFromCoordinateBounds(MGLCoordinateBo MGLLatLngFromLocationCoordinate2D(coordinateBounds.ne)); } -NS_INLINE CLLocationCoordinate2D* MGLLocationCoordinatesFromCoordinateBounds(MGLCoordinateBounds coordinateBounds) { - CLLocationCoordinate2D coordinates[] = { - {coordinateBounds.ne.latitude, coordinateBounds.sw.longitude}, - coordinateBounds.sw, - {coordinateBounds.sw.latitude, coordinateBounds.ne.longitude}, - coordinateBounds.ne, - }; - return coordinates; +NS_INLINE void MGLLocationCoordinatesFromCoordinateBounds(MGLCoordinateBounds coordinateBounds, CLLocationCoordinate2D *coordinates) { + assert(sizeof(coordinates) == 4 * sizeof(CLLocationCoordinate2D)); + coordinates[0] = { coordinateBounds.ne.latitude, coordinateBounds.sw.longitude }; + coordinates[1] = coordinateBounds.sw; + coordinates[2] = { coordinateBounds.sw.latitude, coordinateBounds.ne.longitude }; + coordinates[3] = coordinateBounds.ne; } #if TARGET_OS_IPHONE diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index b0142438297..0d8dd9dd753 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2340,12 +2340,15 @@ - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEd edgePadding:insets direction:self.direction]) return; - CLLocationCoordinate2D *coordinates = MGLLocationCoordinatesFromCoordinateBounds(bounds); + CLLocationCoordinate2D *coordinates = (CLLocationCoordinate2D *)malloc(4 * sizeof(CLLocationCoordinate2D)); + MGLLocationCoordinatesFromCoordinateBounds(bounds, coordinates); [self setVisibleCoordinates:coordinates - count:sizeof(coordinates) / sizeof(coordinates[0]) + count:4 edgePadding:insets animated:animated]; + + free(coordinates); } - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction animated:(BOOL)animated @@ -2354,13 +2357,16 @@ - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEd edgePadding:insets direction:direction]) return; - CLLocationCoordinate2D *coordinates = MGLLocationCoordinatesFromCoordinateBounds(bounds); + CLLocationCoordinate2D *coordinates = (CLLocationCoordinate2D *)malloc(4 * sizeof(CLLocationCoordinate2D)); + MGLLocationCoordinatesFromCoordinateBounds(bounds, coordinates); [self setVisibleCoordinates:coordinates - count:sizeof(coordinates) / sizeof(coordinates[0]) + count:4 edgePadding:insets direction:direction animated:animated]; + + free(coordinates); } - (void)setVisibleCoordinates:(CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated @@ -2781,13 +2787,16 @@ - (BOOL)viewportWouldChangeWithCenterCoordinate:(CLLocationCoordinate2D)centerCo - (BOOL)viewportWouldChangeWithVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction { - CLLocationCoordinate2D *coordinates = MGLLocationCoordinatesFromCoordinateBounds(bounds); + CLLocationCoordinate2D *coordinates = (CLLocationCoordinate2D *)malloc(4 * sizeof(CLLocationCoordinate2D)); + MGLLocationCoordinatesFromCoordinateBounds(bounds, coordinates); const mbgl::CameraOptions cameraOptions = [self cameraOptionsForVisibleCoordinates:coordinates - count:sizeof(coordinates) / sizeof(coordinates[0]) + count:4 edgePadding:insets direction:direction]; + free(coordinates); + return [self viewportWouldChangeWithCamera:[self cameraForCameraOptions:cameraOptions]]; }