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

Commit 49bfdd6

Browse files
committed
[ios, osx] Optional peak altitude for flying
1 parent b7223f2 commit 49bfdd6

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

include/mbgl/ios/MGLMapView.h

+10
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ IB_DESIGNABLE
235235
* @param completion The block to execute after the animation finishes. */
236236
- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion;
237237

238+
/** Moves the viewpoint to a different location using a transition animation that evokes powered flight and an optional transition duration and peak altitude.
239+
*
240+
* The transition animation seamlessly incorporates zooming and panning to help the user find his or her bearings even after traversing a great distance.
241+
*
242+
* @param camera The new viewpoint.
243+
* @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.
244+
* @param peakAltitude The altitude, measured in meters, at the midpoint of the animation. The value of this parameter is ignored if it is negative or if the animation transition resulting from a similar call to `-setCamera:animated:` would have a midpoint at a higher altitude.
245+
* @param completion The block to execute after the animation finishes. */
246+
- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration peakAltitude:(CLLocationDistance)peakAltitude completionHandler:(nullable void (^)(void))completion;
247+
238248
#pragma mark - Converting Map Coordinates
239249

240250
/** @name Converting Map Coordinates */

include/mbgl/osx/MGLMapView.h

+19
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,25 @@ IB_DESIGNABLE
274274
@param completion The block to execute after the animation finishes. */
275275
- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion;
276276

277+
/** Moves the viewpoint to a different location using a transition animation
278+
that evokes powered flight and an optional transition duration and peak
279+
altitude.
280+
281+
The transition animation seamlessly incorporates zooming and panning to help
282+
the user find his or her bearings even after traversing a great distance.
283+
284+
@param camera The new viewpoint.
285+
@param duration The amount of time, measured in seconds, that the transition
286+
animation should take. Specify `0` to jump to the new viewpoint
287+
instantaneously. Specify a negative value to use the default duration,
288+
which is based on the length of the flight path.
289+
@param peakAltitude The altitude, measured in meters, at the midpoint of the
290+
animation. The value of this parameter is ignored if it is negative or
291+
if the animation transition resulting from a similar call to
292+
`-setCamera:animated:` would have a midpoint at a higher altitude.
293+
@param completion The block to execute after the animation finishes. */
294+
- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration peakAltitude:(CLLocationDistance)peakAltitude completionHandler:(nullable void (^)(void))completion;
295+
277296
/** The geographic coordinate bounds visible in the receiver’s viewport.
278297
279298
Changing the value of this property updates the receiver immediately. If you

platform/ios/src/MGLMapView.mm

+14-2
Original file line numberDiff line numberDiff line change
@@ -1750,12 +1750,12 @@ - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration a
17501750

17511751
- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion
17521752
{
1753+
_mbglMap->cancelTransitions();
17531754
if ([self.camera isEqual:camera])
17541755
{
17551756
return;
17561757
}
17571758

1758-
_mbglMap->cancelTransitions();
17591759
mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
17601760
if (duration > 0)
17611761
{
@@ -1783,17 +1783,29 @@ - (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)(
17831783

17841784
- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion
17851785
{
1786+
[self flyToCamera:camera withDuration:duration peakAltitude:-1 completionHandler:completion];
1787+
}
1788+
1789+
- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration peakAltitude:(CLLocationDistance)peakAltitude completionHandler:(nullable void (^)(void))completion
1790+
{
1791+
_mbglMap->cancelTransitions();
17861792
if ([self.camera isEqual:camera])
17871793
{
17881794
return;
17891795
}
17901796

1791-
_mbglMap->cancelTransitions();
17921797
mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
17931798
if (duration >= 0)
17941799
{
17951800
options.duration = MGLDurationInSeconds(duration);
17961801
}
1802+
if (peakAltitude >= 0)
1803+
{
1804+
CLLocationDegrees peakLatitude = (self.centerCoordinate.latitude + camera.centerCoordinate.latitude) / 2;
1805+
CLLocationDegrees peakPitch = (self.camera.pitch + camera.pitch) / 2;
1806+
options.minZoom = MGLZoomLevelForAltitude(peakAltitude, peakPitch,
1807+
peakLatitude, self.frame.size);
1808+
}
17971809
if (completion)
17981810
{
17991811
options.transitionFinishFn = [completion]() {

platform/osx/src/MGLMapView.mm

+10
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,10 @@ - (void)flyToCamera:(MGLMapCamera *)camera completionHandler:(nullable void (^)(
976976
}
977977

978978
- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion {
979+
[self flyToCamera:camera withDuration:duration peakAltitude:-1 completionHandler:completion];
980+
}
981+
982+
- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration peakAltitude:(CLLocationDistance)peakAltitude completionHandler:(nullable void (^)(void))completion {
979983
_mbglMap->cancelTransitions();
980984
if ([self.camera isEqual:camera]) {
981985
return;
@@ -985,6 +989,12 @@ - (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration
985989
if (duration >= 0) {
986990
options.duration = MGLDurationInSeconds(duration);
987991
}
992+
if (peakAltitude >= 0) {
993+
CLLocationDegrees peakLatitude = (self.centerCoordinate.latitude + camera.centerCoordinate.latitude) / 2;
994+
CLLocationDegrees peakPitch = (self.camera.pitch + camera.pitch) / 2;
995+
options.minZoom = MGLZoomLevelForAltitude(peakAltitude, peakPitch,
996+
peakLatitude, self.frame.size);
997+
}
988998
if (completion) {
989999
options.transitionFinishFn = [completion]() {
9901000
// Must run asynchronously after the transition is completely over.

0 commit comments

Comments
 (0)