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

Commit

Permalink
[ios, osx] Allow zero-duration flight
Browse files Browse the repository at this point in the history
For consistency with -setCamera:…, a duration of 0 jumps instantaneously to the new location, while a negative value uses the distance-dependent default.

Due to the produced curve and applied easing, flyTo() doesn’t model a parabola or ballistic trajectory, but it does simulate powered flight to some extent.
  • Loading branch information
1ec5 committed Dec 20, 2015
1 parent 0a9b6a8 commit 2cb70ea
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
12 changes: 9 additions & 3 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,20 @@ 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.
/** 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 path.
*
* The transition animation seamlessly incorporates zooming and panning to help the user find his or her bearings even after traversing a great distance.
*
* @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.
/** Moves the viewpoint to a different location using a transition animation that evokes powered flight and an optional transition duration.
*
* The transition animation seamlessly incorporates zooming and panning to help the user find his or her bearings even after traversing a great distance.
*
* @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 duration The amount of time, measured in seconds, that the transition animation should take. Specify `0` to jump to the new viewpoint instantaneously. Specify a negative value 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
21 changes: 14 additions & 7 deletions include/mbgl/osx/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,28 @@ 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.
/** 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 path.
The transition animation seamlessly incorporates zooming and panning to help
the user find his or her bearings even after traversing a great distance.
@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.
/** Moves the viewpoint to a different location using a transition animation
that evokes powered flight and an optional transition duration.
The transition animation seamlessly incorporates zooming and panning to help
the user find his or her bearings even after traversing a great distance.
@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.
animation should take. Specify `0` to jump to the new viewpoint
instantaneously. Specify a negative value 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
4 changes: 2 additions & 2 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1813,14 +1813,14 @@ - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration a

- (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)(void))completion
{
[self flyToCamera:camera withDuration:0 completionHandler:completion];
[self flyToCamera:camera withDuration:-1 completionHandler:completion];
}

- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion
{
_mbglMap->cancelTransitions();
mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
if (duration > 0)
if (duration >= 0)
{
options.duration = MGLDurationInSeconds(duration);
}
Expand Down
4 changes: 2 additions & 2 deletions platform/osx/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1009,14 +1009,14 @@ - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration a
}

- (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)(void))completion {
[self flyToCamera:camera withDuration:0 completionHandler:completion];
[self flyToCamera:camera withDuration:-1 completionHandler:completion];
}

- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion {
_mbglMap->cancelTransitions();

mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
if (duration > 0) {
if (duration >= 0) {
options.duration = MGLDurationInSeconds(duration);
}
if (completion) {
Expand Down

0 comments on commit 2cb70ea

Please sign in to comment.