From 8f568f32d617a5851d2cc8740ae482c238671f7c Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Fri, 23 Aug 2019 15:49:09 -0400 Subject: [core] Call transitionFinishFn for jumpTo, and in case of NaN parameters. --- include/mbgl/map/camera.hpp | 4 ++++ src/mbgl/map/transform.cpp | 12 +++++++++--- src/mbgl/map/transform.hpp | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/mbgl/map/camera.hpp b/include/mbgl/map/camera.hpp index c8b665fc16..456c0eeb56 100644 --- a/include/mbgl/map/camera.hpp +++ b/include/mbgl/map/camera.hpp @@ -94,6 +94,10 @@ struct AnimationOptions { /** Creates an animation with the specified duration. */ AnimationOptions(Duration d) : duration(d) {} + + AnimationOptions(std::function finish) + : transitionFinishFn(finish) {} + }; } // namespace mbgl diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index d386898c3b..495aacd9bd 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -72,8 +72,8 @@ CameraOptions Transform::getCameraOptions(const EdgeInsets& padding) const { * a transition. The map will retain the current values for any options * not included in `options`. */ -void Transform::jumpTo(const CameraOptions& camera) { - easeTo(camera); + void Transform::jumpTo(const CameraOptions& camera, const AnimationOptions& animation) { + easeTo(camera, animation); } /** @@ -96,6 +96,9 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim double pitch = camera.pitch ? *camera.pitch * util::DEG2RAD : getPitch(); if (std::isnan(zoom) || std::isnan(bearing) || std::isnan(pitch)) { + if (animation.transitionFinishFn) { + animation.transitionFinishFn(); + } return; } @@ -172,6 +175,9 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima double pitch = camera.pitch ? *camera.pitch * util::DEG2RAD : getPitch(); if (std::isnan(zoom) || std::isnan(bearing) || std::isnan(pitch) || state.size.isEmpty()) { + if (animation.transitionFinishFn) { + animation.transitionFinishFn(); + } return; } @@ -273,7 +279,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima } if (duration == Duration::zero()) { // Perform an instantaneous transition. - jumpTo(camera); + jumpTo(camera, animation.transitionFinishFn); return; } diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index ffeff3859c..8fdfb333f3 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -32,7 +32,7 @@ public: CameraOptions getCameraOptions(const EdgeInsets&) const; /** Instantaneously, synchronously applies the given camera options. */ - void jumpTo(const CameraOptions&); + void jumpTo(const CameraOptions&, const AnimationOptions& = {}); /** Asynchronously transitions all specified camera options linearly along an optional time curve. However, center coordinate is not transitioned linearly as, instead, ground speed is kept linear.*/ -- cgit v1.2.1