From 4e0e8166539a03fb5180b813b27d8fff87850a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Tue, 15 Dec 2015 12:51:15 -0800 Subject: [PATCH] [ios, osx] Added flyToCamera: variation that uses default duration --- include/mbgl/ios/MGLMapView.h | 11 ++++++++--- include/mbgl/osx/MGLMapView.h | 12 ++++++++++-- ios/app/MBXViewController.mm | 2 +- platform/ios/MGLMapView.mm | 5 +++++ platform/osx/app/AppDelegate.m | 2 +- platform/osx/src/MGLMapView.mm | 4 ++++ 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index e122874e3..f9c829622 100644 --- a/include/mbgl/ios/MGLMapView.h +++ b/include/mbgl/ios/MGLMapView.h @@ -218,10 +218,15 @@ IB_DESIGNABLE * @param completion The block to execute after the animation finishes. */ - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion; +/** Uses a ballistic parabolic motion to "fly" the viewpoint to a different location with respect to the map with a default duration based on the length of the flight path. +* @param camera The new viewpoint. +* @param completion The block to execute after the animation finishes. */ +- (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)(void))completion; + /** Uses a ballistic parabolic motion to "fly" the viewpoint to a different location with respect to the map with an optional transition duration. - * @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 completion The block to execute after the animation finishes. */ +* @param camera The new viewpoint. +* @param duration The amount of time, measured in seconds, that the transition animation should take. Specify `0` to use the default duration, which is based on the length of the flight path. +* @param completion The block to execute after the animation finishes. */ - (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion; #pragma mark - Converting Map Coordinates diff --git a/include/mbgl/osx/MGLMapView.h b/include/mbgl/osx/MGLMapView.h index 5241329f3..40fd2a6bc 100644 --- a/include/mbgl/osx/MGLMapView.h +++ b/include/mbgl/osx/MGLMapView.h @@ -249,13 +249,21 @@ IB_DESIGNABLE @param completion The block to execute after the animation finishes. */ - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion; +/** Uses a ballistic parabolic motion to “fly” the viewpoint to a different + location with respect to the map with a default duration based on the length + of the flight path. + + @param camera The new viewpoint. + @param completion The block to execute after the animation finishes. */ +- (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)(void))completion; + /** Uses a ballistic parabolic motion to “fly” the viewpoint to a different location with respect to the map with an optional transition duration. @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. + animation should take. Specify `0` to use the default duration, which is + based on the length of the flight path. @param completion The block to execute after the animation finishes. */ - (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion; diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm index d8261395c..7e19382f9 100644 --- a/ios/app/MBXViewController.mm +++ b/ios/app/MBXViewController.mm @@ -379,7 +379,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = { pitch:arc4random_uniform(60) heading:arc4random_uniform(360)]; __weak MBXViewController *weakSelf = self; - [self.mapView flyToCamera:camera withDuration:0 completionHandler:^{ + [self.mapView flyToCamera:camera completionHandler:^{ MBXViewController *strongSelf = weakSelf; [strongSelf performSelector:@selector(continueWorldTourWithRemainingAnnotations:) withObject:annotations diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 83244372f..9050773a8 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -1808,6 +1808,11 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration) [self didChangeValueForKey:@"camera"]; } +- (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)(void))completion +{ + [self flyToCamera:camera withDuration:0 completionHandler:completion]; +} + - (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion { _mbglMap->cancelTransitions(); diff --git a/platform/osx/app/AppDelegate.m b/platform/osx/app/AppDelegate.m index 1229e12a3..bb3961388 100644 --- a/platform/osx/app/AppDelegate.m +++ b/platform/osx/app/AppDelegate.m @@ -319,7 +319,7 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = { pitch:arc4random_uniform(60) heading:arc4random_uniform(360)]; __weak AppDelegate *weakSelf = self; - [self.mapView flyToCamera:camera withDuration:0 completionHandler:^{ + [self.mapView flyToCamera:camera completionHandler:^{ AppDelegate *strongSelf = weakSelf; [strongSelf performSelector:@selector(continueWorldTourWithRemainingAnnotations:) withObject:annotations diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index 40e37bac2..8767c3041 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -1008,6 +1008,10 @@ public: [self didChangeValueForKey:@"camera"]; } +- (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)(void))completion { + [self flyToCamera:camera withDuration:0 completionHandler:completion]; +} + - (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion { _mbglMap->cancelTransitions();