From 71f66493b5e09a2c3fa571c029fc07f10a65af85 Mon Sep 17 00:00:00 2001 From: Asheem Mamoowala Date: Wed, 4 Oct 2017 17:26:03 -0700 Subject: [macOS] Add -[MGLMapView setCamera: withDuration: animationTimingFunction: edgePadding: completionHandler:] for parity with iOS --- platform/macos/src/MGLMapView.h | 31 ++++++++++++++++++------------- platform/macos/src/MGLMapView.mm | 37 ++++++++----------------------------- 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/platform/macos/src/MGLMapView.h b/platform/macos/src/MGLMapView.h index 073c8d4a97..242f3f1e13 100644 --- a/platform/macos/src/MGLMapView.h +++ b/platform/macos/src/MGLMapView.h @@ -323,6 +323,24 @@ MGL_EXPORT IB_DESIGNABLE */ - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion; + /** + Moves the viewpoint to a different location with respect to the map with an + optional transition duration and timing function. + + @param camera The new viewpoint. + @param duration The amount of time, measured in seconds, that the transition + animation should take. Specify `0` to jump to the new viewpoint + instantaneously. + @param function A timing function used for the animation. Set this parameter to + `nil` for a transition that matches most system animations. If the duration + is `0`, this parameter is ignored. + @param edgePadding The minimum padding (in screen points) that would be visible + around the returned camera object if it were set as the receiver’s camera. + @param completion The block to execute after the animation finishes. + */ +- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function edgePadding:(NSEdgeInsets)edgePadding completionHandler:(nullable void (^)(void))completion; + + /** Moves the viewpoint to a different location using a transition animation that evokes powered flight and a default duration based on the length of the flight @@ -403,19 +421,6 @@ MGL_EXPORT IB_DESIGNABLE */ - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated; -/** - Changes the receiver’s viewport to fit the given shape, with the specified direction, - and optionally some additional padding on each side. - - @param shape The shape that the viewport will show in its entirety. - @param direction The direction of the viewport, measured in degrees clockwise from true north. - @param insets The minimum padding (in screen points) that will be visible - around the given coordinate bounds. - @param animated Specify `YES` to animate the change by smoothly scrolling and - zooming or `NO` to immediately display the given bounds. - */ -- (void)setVisibleShape:(MGLShape *)shape direction:(double)direction edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated; - /** Sets the visible region so that the map displays the specified annotations. diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 985a1b71c9..2966f378a0 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -1122,6 +1122,10 @@ public: } - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion { + [self setCamera:camera withDuration:duration animationTimingFunction:function edgePadding:self.contentInsets completionHandler:completion]; +} + +- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function edgePadding:(NSEdgeInsets)edgePadding completionHandler:(nullable void (^)(void))completion { mbgl::AnimationOptions animationOptions; if (duration > 0) { animationOptions.duration.emplace(MGLDurationFromTimeInterval(duration)); @@ -1149,7 +1153,7 @@ public: [self willChangeValueForKey:@"camera"]; _mbglMap->cancelTransitions(); - mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera]; + mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera edgePadding:edgePadding]; _mbglMap->easeTo(cameraOptions, animationOptions); [self didChangeValueForKey:@"camera"]; } @@ -1195,17 +1199,17 @@ public: [self willChangeValueForKey:@"camera"]; _mbglMap->cancelTransitions(); - mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera]; + mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera edgePadding:self.contentInsets]; _mbglMap->flyTo(cameraOptions, animationOptions); [self didChangeValueForKey:@"camera"]; } /// Returns a CameraOptions object that specifies parameters for animating to /// the given camera. -- (mbgl::CameraOptions)cameraOptionsObjectForAnimatingToCamera:(MGLMapCamera *)camera { +- (mbgl::CameraOptions)cameraOptionsObjectForAnimatingToCamera:(MGLMapCamera *)camera edgePadding:(NSEdgeInsets) edgePadding { mbgl::CameraOptions options; options.center = MGLLatLngFromLocationCoordinate2D(camera.centerCoordinate); - options.padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); + options.padding = MGLEdgeInsetsFromNSEdgeInsets(edgePadding); options.zoom = MGLZoomLevelForAltitude(camera.altitude, camera.pitch, camera.centerCoordinate.latitude, self.frame.size); @@ -1257,31 +1261,6 @@ public: _mbglMap->easeTo(cameraOptions, animationOptions); } -- (void)setVisibleShape:(MGLShape *)shape direction:(double)direction edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated { - _mbglMap->cancelTransitions(); - - mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); - padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets); - - mbgl::CameraOptions cameraOptions = _mbglMap->cameraForGeometry([shape geometryObject], padding, direction); - - mbgl::AnimationOptions animationOptions; - if (animated) { - animationOptions.duration = MGLDurationFromTimeInterval(MGLAnimationDuration); - } - - MGLMapCamera *camera = [self cameraForCameraOptions:cameraOptions]; - if ([self.camera isEqualToMapCamera:camera]) { - return; - } - - [self willChangeValueForKey:@"visibleCoordinateBounds"]; - animationOptions.transitionFinishFn = ^() { - [self didChangeValueForKey:@"visibleCoordinateBounds"]; - }; - _mbglMap->easeTo(cameraOptions, animationOptions); -} - - (MGLMapCamera *)cameraThatFitsCoordinateBounds:(MGLCoordinateBounds)bounds { return [self cameraThatFitsCoordinateBounds:bounds edgePadding:NSEdgeInsetsZero]; } -- cgit v1.2.1