From cf43870ebe522d6a28f253fe7fedd56b1a75df7a Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Mon, 25 Jun 2018 12:44:13 -0700 Subject: [PATCH 01/16] Add pitch argument to cameraThatFits functions --- include/mbgl/map/map.hpp | 6 +++--- platform/ios/src/MGLMapView.h | 4 ++++ platform/ios/src/MGLMapView.mm | 20 ++++++++++++++++++-- src/mbgl/map/map.cpp | 11 ++++++----- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 5ba23a76dd0..3aee9320703 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -67,9 +67,9 @@ class Map : private util::noncopyable { void jumpTo(const CameraOptions&); void easeTo(const CameraOptions&, const AnimationOptions&); void flyTo(const CameraOptions&, const AnimationOptions&); - CameraOptions cameraForLatLngBounds(const LatLngBounds&, const EdgeInsets&, optional bearing = {}) const; - CameraOptions cameraForLatLngs(const std::vector&, const EdgeInsets&, optional bearing = {}) const; - CameraOptions cameraForGeometry(const Geometry&, const EdgeInsets&, optional bearing = {}) const; + CameraOptions cameraForLatLngBounds(const LatLngBounds&, const EdgeInsets&, optional bearing = {}, optional pitch = {}) const; + CameraOptions cameraForLatLngs(const std::vector&, const EdgeInsets&, optional bearing = {}, optional pitch = {}) const; + CameraOptions cameraForGeometry(const Geometry&, const EdgeInsets&, optional bearing = {}, optional pitch = {}) const; LatLngBounds latLngBoundsForCamera(const CameraOptions&) const; // Position diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index fd0ca19b26a..6f01beed51e 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -926,6 +926,8 @@ MGL_EXPORT IB_DESIGNABLE */ - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets; +- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets pitch:(CLLocationDirection)pitch; + /** Returns the camera that best fits the given shape, with the specified direction, optionally with some additional padding on each side. @@ -940,6 +942,8 @@ MGL_EXPORT IB_DESIGNABLE */ - (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets; +- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets pitch:(CLLocationDirection)pitch; + /** Returns the point in this view’s coordinate system on which to "anchor" in response to a user-initiated gesture. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 7003f2e4b4c..be26d72e21e 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3348,14 +3348,30 @@ - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edg return [self cameraForCameraOptions:cameraOptions]; } -- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets { +- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets pitch:(CLLocationDirection)pitch +{ mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); + mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding, pitch); + return [self cameraForCameraOptions:cameraOptions]; +} +- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets { + mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); + padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); + mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction); - + return [self cameraForCameraOptions:cameraOptions]; +} + +- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets pitch:(CLLocationDirection)pitch { + mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); + padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); + mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction, pitch); + + return [self cameraForCameraOptions:cameraOptions]; } - (MGLMapCamera *)cameraForCameraOptions:(const mbgl::CameraOptions &)cameraOptions diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index ea35560e97a..d8bf45cae64 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -364,13 +364,13 @@ void Map::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInsets& pad impl->onUpdate(); } -CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, const EdgeInsets& padding, optional bearing) const { +CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, const EdgeInsets& padding, optional bearing, optional pitch) const { return cameraForLatLngs({ bounds.northwest(), bounds.southwest(), bounds.southeast(), bounds.northeast(), - }, padding, bearing); + }, padding, bearing, pitch); } CameraOptions cameraForLatLngs(const std::vector& latLngs, const Transform& transform, const EdgeInsets& padding) { @@ -426,26 +426,27 @@ CameraOptions cameraForLatLngs(const std::vector& latLngs, const Transfo return options; } -CameraOptions Map::cameraForLatLngs(const std::vector& latLngs, const EdgeInsets& padding, optional bearing) const { +CameraOptions Map::cameraForLatLngs(const std::vector& latLngs, const EdgeInsets& padding, optional bearing, optional pitch) const { if(bearing) { double angle = -*bearing * util::DEG2RAD; // Convert to radians Transform transform(impl->transform.getState()); transform.setAngle(angle); CameraOptions options = mbgl::cameraForLatLngs(latLngs, transform, padding); options.angle = angle; + options.pitch = pitch; return options; } else { return mbgl::cameraForLatLngs(latLngs, impl->transform, padding); } } -CameraOptions Map::cameraForGeometry(const Geometry& geometry, const EdgeInsets& padding, optional bearing) const { +CameraOptions Map::cameraForGeometry(const Geometry& geometry, const EdgeInsets& padding, optional bearing, optional pitch) const { std::vector latLngs; forEachPoint(geometry, [&](const Point& pt) { latLngs.push_back({ pt.y, pt.x }); }); - return cameraForLatLngs(latLngs, padding, bearing); + return cameraForLatLngs(latLngs, padding, bearing, pitch); } LatLngBounds Map::latLngBoundsForCamera(const CameraOptions& camera) const { From 073e49796d71a473f2f068dd70b8ff32c1ce69a0 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Mon, 25 Jun 2018 13:00:57 -0700 Subject: [PATCH 02/16] check if nil --- src/mbgl/map/map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index d8bf45cae64..a89e1be7e29 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -427,7 +427,7 @@ CameraOptions cameraForLatLngs(const std::vector& latLngs, const Transfo } CameraOptions Map::cameraForLatLngs(const std::vector& latLngs, const EdgeInsets& padding, optional bearing, optional pitch) const { - if(bearing) { + if (bearing && pitch) { double angle = -*bearing * util::DEG2RAD; // Convert to radians Transform transform(impl->transform.getState()); transform.setAngle(angle); From 74a166af70c37d0dc4ba85bc2d04a58038feed12 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Tue, 26 Jun 2018 10:25:26 -0700 Subject: [PATCH 03/16] Change around --- platform/ios/src/MGLMapView.h | 33 +++++++++++++++++++++++++++++++-- platform/ios/src/MGLMapView.mm | 6 +++--- src/mbgl/map/map.cpp | 32 +++++++++++++++++++++++--------- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 6f01beed51e..47ad2da28f9 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -926,7 +926,22 @@ MGL_EXPORT IB_DESIGNABLE */ - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets; -- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets pitch:(CLLocationDirection)pitch; +/** + Returns the camera that best fits the given coordinate bounds, optionally with + some additional padding on each side. + + @param bounds The coordinate bounds to fit to the receiver’s viewport. + @param direction The direction of the viewport, measured in degrees clockwise from true north. + @param pitch The viewing angle of the camera, measured in degrees. A value of + `0` results in a camera pointed straight down at the map. Angles greater + than `0` result in a camera angled toward the horizon. + @param insets The minimum padding (in screen points) that would be visible + around the returned camera object if it were set as the receiver’s camera. + @return A camera object centered on the same location as the coordinate bounds + with zoom level as high (close to the ground) as possible while still + including the entire coordinate bounds. + */ +- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds direction:(CLLocationDirection)direction pitch:(CGFloat)pitch edgePadding:(UIEdgeInsets)insets; /** Returns the camera that best fits the given shape, with the specified direction, @@ -942,7 +957,21 @@ MGL_EXPORT IB_DESIGNABLE */ - (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets; -- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets pitch:(CLLocationDirection)pitch; +/** + Returns the camera that best fits the given shape, with the specified direction and pitch, + optionally with some additional padding on each side. + + @param shape The shape to fit to the receiver’s viewport. + @param direction The direction of the viewport, measured in degrees clockwise from true north. + @param pitch The viewing angle of the camera, measured in degrees. A value of + `0` results in a camera pointed straight down at the map. Angles greater + than `0` result in a camera angled toward the horizon. + @param insets The minimum padding (in screen points) that would be visible + around the returned camera object if it were set as the receiver’s camera. + @return A camera object centered on the shape's center with zoom level as high + (close to the ground) as possible while still including the entire shape. + */ +- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction pitch:(CGFloat)pitch edgePadding:(UIEdgeInsets)insets; /** Returns the point in this view’s coordinate system on which to "anchor" in diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index be26d72e21e..1a98a07d6c4 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3348,11 +3348,11 @@ - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edg return [self cameraForCameraOptions:cameraOptions]; } -- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets pitch:(CLLocationDirection)pitch +- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds direction:(CLLocationDirection)direction pitch:(CGFloat)pitch edgePadding:(UIEdgeInsets)insets { mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); - mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding, pitch); + mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding, direction, pitch); return [self cameraForCameraOptions:cameraOptions]; } @@ -3365,7 +3365,7 @@ - (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDir return [self cameraForCameraOptions:cameraOptions]; } -- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets pitch:(CLLocationDirection)pitch { +- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction pitch:(CGFloat)pitch edgePadding:(UIEdgeInsets)insets { mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index a89e1be7e29..972c03eead7 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -427,17 +427,31 @@ CameraOptions cameraForLatLngs(const std::vector& latLngs, const Transfo } CameraOptions Map::cameraForLatLngs(const std::vector& latLngs, const EdgeInsets& padding, optional bearing, optional pitch) const { - if (bearing && pitch) { - double angle = -*bearing * util::DEG2RAD; // Convert to radians - Transform transform(impl->transform.getState()); - transform.setAngle(angle); - CameraOptions options = mbgl::cameraForLatLngs(latLngs, transform, padding); - options.angle = angle; - options.pitch = pitch; - return options; - } else { + + if (!bearing && !pitch) { return mbgl::cameraForLatLngs(latLngs, impl->transform, padding); } + + Transform transform(impl->transform.getState()); + + if (bearing) { + double angle = -*bearing * util::DEG2RAD; // Convert to radians + transform.setAngle(angle); + } + if (pitch) { + transform.setPitch(*pitch); + } + + CameraOptions options = mbgl::cameraForLatLngs(latLngs, transform, padding); + + if (bearing) { + options.angle = transform.getAngle(); + } + if (pitch) { + options.angle = transform.getAngle(); + } + + return options; } CameraOptions Map::cameraForGeometry(const Geometry& geometry, const EdgeInsets& padding, optional bearing, optional pitch) const { From 6de4b0a72a5e00ddeb60ddf76b7f5ca1bd193f30 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Wed, 27 Jun 2018 08:42:16 -0700 Subject: [PATCH 04/16] fix copy pasta --- src/mbgl/map/map.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 972c03eead7..0d1cd3565e1 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -443,13 +443,8 @@ CameraOptions Map::cameraForLatLngs(const std::vector& latLngs, const Ed } CameraOptions options = mbgl::cameraForLatLngs(latLngs, transform, padding); - - if (bearing) { - options.angle = transform.getAngle(); - } - if (pitch) { - options.angle = transform.getAngle(); - } + options.angle = transform.getAngle(); + options.pitch = transform.getPitch(); return options; } From d72d77b3a236d3a70f9c85a89c2b781c5201cc40 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Wed, 27 Jun 2018 10:05:55 -0700 Subject: [PATCH 05/16] Round --- test/map/map.test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index f95e26fd825..19571334304 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -84,7 +84,7 @@ TEST(Map, LatLngBoundsToCameraWithAngle) { CameraOptions virtualCamera = test.map.cameraForLatLngBounds(bounds, {}, 35); ASSERT_TRUE(bounds.contains(*virtualCamera.center)); EXPECT_NEAR(*virtualCamera.zoom, 1.21385, 1e-5); - EXPECT_DOUBLE_EQ(virtualCamera.angle.value_or(0), -35 * util::DEG2RAD); + EXPECT_NEAR(virtualCamera.angle.value_or(0), -35 * util::DEG2RAD, 1e-6); } TEST(Map, LatLngsToCamera) { From 3c273bc176669f86dfce0c838e93b8895fd07c54 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Wed, 27 Jun 2018 11:08:37 -0700 Subject: [PATCH 06/16] use rad --- src/mbgl/map/map.cpp | 3 ++- test/map/map.test.cpp | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 0d1cd3565e1..6c8f48501b7 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -439,7 +439,8 @@ CameraOptions Map::cameraForLatLngs(const std::vector& latLngs, const Ed transform.setAngle(angle); } if (pitch) { - transform.setPitch(*pitch); + double pichAsRadian = *pitch * util::DEG2RAD; // Convert to radians + transform.setPitch(pichAsRadian); } CameraOptions options = mbgl::cameraForLatLngs(latLngs, transform, padding); diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 19571334304..4f7bd2df7b4 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -84,7 +84,21 @@ TEST(Map, LatLngBoundsToCameraWithAngle) { CameraOptions virtualCamera = test.map.cameraForLatLngBounds(bounds, {}, 35); ASSERT_TRUE(bounds.contains(*virtualCamera.center)); EXPECT_NEAR(*virtualCamera.zoom, 1.21385, 1e-5); - EXPECT_NEAR(virtualCamera.angle.value_or(0), -35 * util::DEG2RAD, 1e-6); + EXPECT_NEAR(virtualCamera.angle.value_or(0), -35 * util::DEG2RAD, 1e-5); +} + +TEST(Map, LatLngBoundsToCameraWithAngleAndPitch) { + MapTest<> test; + + test.map.setLatLngZoom({ 40.712730, -74.005953 }, 16.0); + + LatLngBounds bounds = LatLngBounds::hull({15.68169,73.499857}, {53.560711, 134.77281}); + + CameraOptions virtualCamera = test.map.cameraForLatLngBounds(bounds, {}, 35, 20); + ASSERT_TRUE(bounds.contains(*virtualCamera.center)); + EXPECT_NEAR(*virtualCamera.zoom, 13.66272, 1e-5); + ASSERT_DOUBLE_EQ(*virtualCamera.pitch, 20 * util::DEG2RAD); + EXPECT_NEAR(virtualCamera.angle.value_or(0), -35 * util::DEG2RAD, 1e-5); } TEST(Map, LatLngsToCamera) { @@ -93,12 +107,26 @@ TEST(Map, LatLngsToCamera) { std::vector latLngs{{ 40.712730, 74.005953 }, {15.68169,73.499857}, {30.82678, 83.4082}}; CameraOptions virtualCamera = test.map.cameraForLatLngs(latLngs, {}, 23); - EXPECT_DOUBLE_EQ(virtualCamera.angle.value_or(0), -23 * util::DEG2RAD); + EXPECT_NEAR(virtualCamera.angle.value_or(0), -23 * util::DEG2RAD, 1e-5); EXPECT_NEAR(virtualCamera.zoom.value_or(0), 2.75434, 1e-5); EXPECT_NEAR(virtualCamera.center->latitude(), 28.49288, 1e-5); EXPECT_NEAR(virtualCamera.center->longitude(), 74.97437, 1e-5); } +TEST(Map, LatLngsToCameraWithAngleAndPitch) { + MapTest<> test; + + std::vector latLngs{{ 40.712730, 74.005953 }, {15.68169,73.499857}, {30.82678, 83.4082}}; + + CameraOptions virtualCamera = test.map.cameraForLatLngs(latLngs, {}, 23, 20); + EXPECT_NEAR(virtualCamera.angle.value_or(0), -23 * util::DEG2RAD, 1e-5); + EXPECT_NEAR(virtualCamera.zoom.value_or(0), 3.04378, 1e-5); + EXPECT_NEAR(virtualCamera.center->latitude(), 28.53718, 1e-5); + EXPECT_NEAR(virtualCamera.center->longitude(), 74.31746, 1e-5); + ASSERT_DOUBLE_EQ(*virtualCamera.pitch, 20 * util::DEG2RAD); +} + + TEST(Map, CameraToLatLngBounds) { MapTest<> test; From f5f73973acc84fb1e894be03fdceee923e2af7cb Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Wed, 27 Jun 2018 11:13:41 -0700 Subject: [PATCH 07/16] sp --- src/mbgl/map/map.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 6c8f48501b7..c1772994850 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -439,8 +439,8 @@ CameraOptions Map::cameraForLatLngs(const std::vector& latLngs, const Ed transform.setAngle(angle); } if (pitch) { - double pichAsRadian = *pitch * util::DEG2RAD; // Convert to radians - transform.setPitch(pichAsRadian); + double pitchAsRadian = *pitch * util::DEG2RAD; // Convert to radians + transform.setPitch(pitchAsRadian); } CameraOptions options = mbgl::cameraForLatLngs(latLngs, transform, padding); From 3946841733b3f91f23a3eda375476bf69f5a4fe9 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Wed, 27 Jun 2018 11:40:47 -0700 Subject: [PATCH 08/16] retest From 92dac01f0f7f605c3db379851627e1d737ace5cc Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Thu, 28 Jun 2018 14:25:10 -0700 Subject: [PATCH 09/16] Update --- platform/ios/src/MGLMapView.h | 36 +++++++++------------------------- platform/ios/src/MGLMapView.mm | 21 ++++++++------------ 2 files changed, 17 insertions(+), 40 deletions(-) diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 47ad2da28f9..08593d2fde4 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -927,21 +927,19 @@ MGL_EXPORT IB_DESIGNABLE - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets; /** - Returns the camera that best fits the given coordinate bounds, optionally with - some additional padding on each side. + Returns the camera that best fits the given shape, with the specified camera, + optionally with some additional padding on each side. - @param bounds The coordinate bounds to fit to the receiver’s viewport. - @param direction The direction of the viewport, measured in degrees clockwise from true north. - @param pitch The viewing angle of the camera, measured in degrees. A value of - `0` results in a camera pointed straight down at the map. Angles greater - than `0` result in a camera angled toward the horizon. + @param camera The camera the return camera should adhere to. All values + on this camera will be manipulated except for pitch and direction + @param shape The shape to fit to the receiver’s viewport. @param insets The minimum padding (in screen points) that would be visible around the returned camera object if it were set as the receiver’s camera. - @return A camera object centered on the same location as the coordinate bounds - with zoom level as high (close to the ground) as possible while still - including the entire coordinate bounds. + @return A camera object centered on the shape's center with zoom level as high + (close to the ground) as possible while still including the entire shape. The + initial camera's pitch and direction will be honored. */ -- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds direction:(CLLocationDirection)direction pitch:(CGFloat)pitch edgePadding:(UIEdgeInsets)insets; +- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape edgePadding:(UIEdgeInsets)insets; /** Returns the camera that best fits the given shape, with the specified direction, @@ -957,22 +955,6 @@ MGL_EXPORT IB_DESIGNABLE */ - (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets; -/** - Returns the camera that best fits the given shape, with the specified direction and pitch, - optionally with some additional padding on each side. - - @param shape The shape to fit to the receiver’s viewport. - @param direction The direction of the viewport, measured in degrees clockwise from true north. - @param pitch The viewing angle of the camera, measured in degrees. A value of - `0` results in a camera pointed straight down at the map. Angles greater - than `0` result in a camera angled toward the horizon. - @param insets The minimum padding (in screen points) that would be visible - around the returned camera object if it were set as the receiver’s camera. - @return A camera object centered on the shape's center with zoom level as high - (close to the ground) as possible while still including the entire shape. - */ -- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction pitch:(CGFloat)pitch edgePadding:(UIEdgeInsets)insets; - /** Returns the point in this view’s coordinate system on which to "anchor" in response to a user-initiated gesture. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 1a98a07d6c4..3350b1db850 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3348,12 +3348,16 @@ - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edg return [self cameraForCameraOptions:cameraOptions]; } -- (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds direction:(CLLocationDirection)direction pitch:(CGFloat)pitch edgePadding:(UIEdgeInsets)insets -{ +- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape edgePadding:(UIEdgeInsets)insets { mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); - mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding, direction, pitch); - return [self cameraForCameraOptions:cameraOptions]; + + CGFloat pitch = camera.pitch; + CLLocationDirection direction = camera.heading; + + mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction, pitch); + + return [self cameraForCameraOptions: cameraOptions]; } - (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(UIEdgeInsets)insets { @@ -3365,15 +3369,6 @@ - (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDir return [self cameraForCameraOptions:cameraOptions]; } -- (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction pitch:(CGFloat)pitch edgePadding:(UIEdgeInsets)insets { - mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); - padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); - - mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction, pitch); - - return [self cameraForCameraOptions:cameraOptions]; -} - - (MGLMapCamera *)cameraForCameraOptions:(const mbgl::CameraOptions &)cameraOptions { CLLocationCoordinate2D centerCoordinate = MGLLocationCoordinate2DFromLatLng(cameraOptions.center ? *cameraOptions.center : _mbglMap->getLatLng()); From 0dca9d83f16890adecb9ce8eb72e820b167fd1c8 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Thu, 28 Jun 2018 14:33:12 -0700 Subject: [PATCH 10/16] fix --- platform/ios/src/MGLMapView.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 08593d2fde4..6189008d379 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -930,7 +930,7 @@ MGL_EXPORT IB_DESIGNABLE Returns the camera that best fits the given shape, with the specified camera, optionally with some additional padding on each side. - @param camera The camera the return camera should adhere to. All values + @param camera The camera that the return camera should adhere to. All values on this camera will be manipulated except for pitch and direction @param shape The shape to fit to the receiver’s viewport. @param insets The minimum padding (in screen points) that would be visible From 2dab59c7b1db2ef0914665c69db2d178e9f1d884 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Fri, 29 Jun 2018 13:39:32 -0700 Subject: [PATCH 11/16] add camera fitting bounds, add macos --- platform/ios/src/MGLMapView.h | 18 +++++++++++++++++- platform/ios/src/MGLMapView.mm | 12 ++++++++++++ platform/macos/src/MGLMapView.h | 31 +++++++++++++++++++++++++++++++ platform/macos/src/MGLMapView.mm | 24 ++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 6189008d379..04a7a06313a 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -926,12 +926,28 @@ MGL_EXPORT IB_DESIGNABLE */ - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets; +/** + Returns the camera that best fits the given coordinate bounds, with the specified camera, + optionally with some additional padding on each side. + + @param camera The camera that the return camera should adhere to. All values + on this camera will be manipulated except for pitch and direction. + @param bounds The coordinate bounds to fit to the receiver’s viewport. + @param insets The minimum padding (in screen points) that would be visible + around the returned camera object if it were set as the receiver’s camera. + @return A camera object centered on the same location as the coordinate bounds + with zoom level as high (close to the ground) as possible while still + including the entire coordinate bounds. The initial camera's pitch and + direction will be honored. + */ +- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets; + /** Returns the camera that best fits the given shape, with the specified camera, optionally with some additional padding on each side. @param camera The camera that the return camera should adhere to. All values - on this camera will be manipulated except for pitch and direction + on this camera will be manipulated except for pitch and direction. @param shape The shape to fit to the receiver’s viewport. @param insets The minimum padding (in screen points) that would be visible around the returned camera object if it were set as the receiver’s camera. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 3350b1db850..e92cba93dee 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3348,6 +3348,18 @@ - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edg return [self cameraForCameraOptions:cameraOptions]; } +- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets +{ + mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); + padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); + + CGFloat pitch = camera.pitch; + CLLocationDirection direction = camera.heading; + + mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding, direction, pitch); + return [self cameraForCameraOptions:cameraOptions]; +} + - (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape edgePadding:(UIEdgeInsets)insets { mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); diff --git a/platform/macos/src/MGLMapView.h b/platform/macos/src/MGLMapView.h index 824df827ac2..305a1348e4c 100644 --- a/platform/macos/src/MGLMapView.h +++ b/platform/macos/src/MGLMapView.h @@ -485,6 +485,37 @@ MGL_EXPORT IB_DESIGNABLE */ - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets; +/** + Returns the camera that best fits the given coordinate bounds, with the specified camera, + optionally with some additional padding on each side. + + @param camera The camera that the return camera should adhere to. All values + on this camera will be manipulated except for pitch and direction. + @param bounds The coordinate bounds to fit to the receiver’s viewport. + @param insets The minimum padding (in screen points) that would be visible + around the returned camera object if it were set as the receiver’s camera. + @return A camera object centered on the same location as the coordinate bounds + with zoom level as high (close to the ground) as possible while still + including the entire coordinate bounds. The initial camera's pitch and + direction will be honored. + */ +- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets; + +/** + Returns the camera that best fits the given shape, with the specified camera, + optionally with some additional padding on each side. + + @param camera The camera that the return camera should adhere to. All values + on this camera will be manipulated except for pitch and direction. + @param shape The shape to fit to the receiver’s viewport. + @param insets The minimum padding (in screen points) that would be visible + around the returned camera object if it were set as the receiver’s camera. + @return A camera object centered on the shape's center with zoom level as high + (close to the ground) as possible while still including the entire shape. The + initial camera's pitch and direction will be honored. + */ +- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape edgePadding:(NSEdgeInsets)insets; + /** Returns the camera that best fits the given shape, with the specified direction, optionally with some additional padding on each side. diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index bc9ac1e6416..5f4a9609629 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -1275,6 +1275,30 @@ - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds edg return [self cameraForCameraOptions:cameraOptions]; } +- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets +{ + mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); + padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); + + CGFloat pitch = camera.pitch; + CLLocationDirection direction = camera.heading; + + mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding, direction, pitch); + return [self cameraForCameraOptions:cameraOptions]; +} + +- (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape edgePadding:(NSEdgeInsets)insets { + mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); + padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); + + CGFloat pitch = camera.pitch; + CLLocationDirection direction = camera.heading; + + mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction, pitch); + + return [self cameraForCameraOptions: cameraOptions]; +} + - (MGLMapCamera *)cameraThatFitsShape:(MGLShape *)shape direction:(CLLocationDirection)direction edgePadding:(NSEdgeInsets)insets { mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); From 28d2cd793344c8446393f25826a00594e9c82d05 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Fri, 29 Jun 2018 13:43:41 -0700 Subject: [PATCH 12/16] Changelog --- platform/ios/CHANGELOG.md | 4 ++++ platform/macos/CHANGELOG.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index c49dc4381f5..85622d85a73 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -2,6 +2,10 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONTRIBUTING.md](../../CONTRIBUTING.md) to get started. +# master + +* Added `-[MGLMapView camera:fittingShape:edgePadding:]` and `-[MGLMapView camera:fittingCoordinateBounds:edgePadding:]` allowing you specify the pitch and direction for the calculated camera. + ## 4.2.0 ### Packaging diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 7767185c4eb..16d8b186a87 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog for Mapbox Maps SDK for macOS +# master + +* Added `-[MGLMapView camera:fittingShape:edgePadding:]` and `-[MGLMapView camera:fittingCoordinateBounds:edgePadding:]` allowing you specify the pitch and direction for the calculated camera. + ## 0.7.2 - June 22, 2018 * Fixed a crash in `-[MGLStyle localizeLabelsIntoLocale:]` on macOS 10.11. ([#12123](https://github.com/mapbox/mapbox-gl-native/pull/12123)) From cd5828cf73eeb7f158d34b8ca1524f61cf9bdf2c Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Mon, 2 Jul 2018 08:23:38 -0700 Subject: [PATCH 13/16] add link --- platform/ios/CHANGELOG.md | 2 +- platform/macos/CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 85622d85a73..9b377913de0 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -4,7 +4,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT # master -* Added `-[MGLMapView camera:fittingShape:edgePadding:]` and `-[MGLMapView camera:fittingCoordinateBounds:edgePadding:]` allowing you specify the pitch and direction for the calculated camera. +* Added `-[MGLMapView camera:fittingShape:edgePadding:]` and `-[MGLMapView camera:fittingCoordinateBounds:edgePadding:]` allowing you specify the pitch and direction for the calculated camera. ([#12213](https://github.com/mapbox/mapbox-gl-native/pull/12213)) ## 4.2.0 diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 16d8b186a87..f084552b687 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -2,7 +2,7 @@ # master -* Added `-[MGLMapView camera:fittingShape:edgePadding:]` and `-[MGLMapView camera:fittingCoordinateBounds:edgePadding:]` allowing you specify the pitch and direction for the calculated camera. +* Added `-[MGLMapView camera:fittingShape:edgePadding:]` and `-[MGLMapView camera:fittingCoordinateBounds:edgePadding:]` allowing you specify the pitch and direction for the calculated camera. ([#12213](https://github.com/mapbox/mapbox-gl-native/pull/12213)) ## 0.7.2 - June 22, 2018 From 71720d0f043e78d33206735a0b5d953a142de1b8 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Mon, 2 Jul 2018 09:52:21 -0700 Subject: [PATCH 14/16] Dont allow for negative values --- platform/ios/src/MGLMapView.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index e92cba93dee..1cd29ed7adf 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3364,8 +3364,8 @@ - (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape e mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); - CGFloat pitch = camera.pitch; - CLLocationDirection direction = camera.heading; + CGFloat pitch = camera.pitch < 0 ? _mbglMap->getPitch() : camera.pitch; + CLLocationDirection direction = camera.heading < 0 ? _mbglMap->getBearing() : camera.heading; mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction, pitch); From d862574a2117a9ed380d91f3b3f4e00a48224b85 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Mon, 2 Jul 2018 09:53:32 -0700 Subject: [PATCH 15/16] do everywhere --- platform/ios/src/MGLMapView.mm | 4 ++-- platform/macos/src/MGLMapView.mm | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 1cd29ed7adf..616a9a8cd3e 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3353,8 +3353,8 @@ - (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoor mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); - CGFloat pitch = camera.pitch; - CLLocationDirection direction = camera.heading; + CGFloat pitch = camera.pitch < 0 ? _mbglMap->getPitch() : camera.pitch; + CLLocationDirection direction = camera.heading < 0 ? _mbglMap->getBearing() : camera.heading; mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding, direction, pitch); return [self cameraForCameraOptions:cameraOptions]; diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 5f4a9609629..9cb4fe450b7 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -1280,8 +1280,8 @@ - (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoor mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); - CGFloat pitch = camera.pitch; - CLLocationDirection direction = camera.heading; + CGFloat pitch = camera.pitch < 0 ? _mbglMap->getPitch() : camera.pitch; + CLLocationDirection direction = camera.heading < 0 ? _mbglMap->getBearing() : camera.heading; mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding, direction, pitch); return [self cameraForCameraOptions:cameraOptions]; @@ -1291,8 +1291,8 @@ - (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape e mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); - CGFloat pitch = camera.pitch; - CLLocationDirection direction = camera.heading; + CGFloat pitch = camera.pitch < 0 ? _mbglMap->getPitch() : camera.pitch; + CLLocationDirection direction = camera.heading < 0 ? _mbglMap->getBearing() : camera.heading; mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction, pitch); From 110c70b7990b387bb8e23eee20d6c44020e20b8f Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Mon, 2 Jul 2018 15:45:35 -0700 Subject: [PATCH 16/16] Use current camera --- platform/ios/src/MGLMapView.mm | 10 ++++++---- platform/macos/src/MGLMapView.mm | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 616a9a8cd3e..1bbda94387e 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3353,8 +3353,9 @@ - (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoor mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); - CGFloat pitch = camera.pitch < 0 ? _mbglMap->getPitch() : camera.pitch; - CLLocationDirection direction = camera.heading < 0 ? _mbglMap->getBearing() : camera.heading; + MGLMapCamera *currentCamera = self.camera; + CGFloat pitch = camera.pitch < 0 ? currentCamera.pitch : camera.pitch; + CLLocationDirection direction = camera.heading < 0 ? currentCamera.heading : camera.heading; mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding, direction, pitch); return [self cameraForCameraOptions:cameraOptions]; @@ -3364,8 +3365,9 @@ - (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape e mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); - CGFloat pitch = camera.pitch < 0 ? _mbglMap->getPitch() : camera.pitch; - CLLocationDirection direction = camera.heading < 0 ? _mbglMap->getBearing() : camera.heading; + MGLMapCamera *currentCamera = self.camera; + CGFloat pitch = camera.pitch < 0 ? currentCamera.pitch : camera.pitch; + CLLocationDirection direction = camera.heading < 0 ? currentCamera.heading : camera.heading; mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction, pitch); diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 9cb4fe450b7..154b716377f 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -1280,8 +1280,9 @@ - (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingCoordinateBounds:(MGLCoor mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); - CGFloat pitch = camera.pitch < 0 ? _mbglMap->getPitch() : camera.pitch; - CLLocationDirection direction = camera.heading < 0 ? _mbglMap->getBearing() : camera.heading; + MGLMapCamera *currentCamera = self.camera; + CGFloat pitch = camera.pitch < 0 ? currentCamera.pitch : camera.pitch; + CLLocationDirection direction = camera.heading < 0 ? currentCamera.heading : camera.heading; mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), padding, direction, pitch); return [self cameraForCameraOptions:cameraOptions]; @@ -1291,8 +1292,9 @@ - (MGLMapCamera *)camera:(MGLMapCamera *)camera fittingShape:(MGLShape *)shape e mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); - CGFloat pitch = camera.pitch < 0 ? _mbglMap->getPitch() : camera.pitch; - CLLocationDirection direction = camera.heading < 0 ? _mbglMap->getBearing() : camera.heading; + MGLMapCamera *currentCamera = self.camera; + CGFloat pitch = camera.pitch < 0 ? currentCamera.pitch : camera.pitch; + CLLocationDirection direction = camera.heading < 0 ? currentCamera.heading : camera.heading; mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction, pitch);