Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios, osx] Added flyToCamera: variation that uses default duration
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Dec 15, 2015
1 parent 5dd00d1 commit 4e0e816
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
11 changes: 8 additions & 3 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions include/mbgl/osx/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion ios/app/MBXViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ - (void)continueWorldTourWithRemainingAnnotations:(NS_MUTABLE_ARRAY_OF(MGLPointA
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
Expand Down
5 changes: 5 additions & 0 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,11 @@ - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration a
[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();
Expand Down
2 changes: 1 addition & 1 deletion platform/osx/app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ - (void)continueWorldTourWithRemainingAnnotations:(NS_MUTABLE_ARRAY_OF(MGLPointA
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
Expand Down
4 changes: 4 additions & 0 deletions platform/osx/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,10 @@ - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration a
[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();

Expand Down

0 comments on commit 4e0e816

Please sign in to comment.