diff options
author | Bobby Sudekum <bobby@mapbox.com> | 2018-06-26 10:25:26 -0700 |
---|---|---|
committer | Bobby Sudekum <bobby@mapbox.com> | 2018-06-26 10:25:26 -0700 |
commit | 74a166af70c37d0dc4ba85bc2d04a58038feed12 (patch) | |
tree | 0483c4b73ae392b4d869795fcd41e668cd028a00 | |
parent | 073e49796d71a473f2f068dd70b8ff32c1ce69a0 (diff) | |
download | qtlocation-mapboxgl-upstream/cameraThatFitsWithPitch.tar.gz |
Change aroundupstream/cameraThatFitsWithPitch
-rw-r--r-- | platform/ios/src/MGLMapView.h | 33 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 6 | ||||
-rw-r--r-- | 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 6f01beed51..47ad2da28f 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 be26d72e21..1a98a07d6c 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -3348,11 +3348,11 @@ public: 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 @@ public: 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 a89e1be7e2..972c03eead 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -427,17 +427,31 @@ CameraOptions cameraForLatLngs(const std::vector<LatLng>& latLngs, const Transfo } CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const EdgeInsets& padding, optional<double> bearing, optional<double> 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<double>& geometry, const EdgeInsets& padding, optional<double> bearing, optional<double> pitch) const { |