[core] Separated AnimationOptions from CameraOptions
This commit is contained in:
@@ -11,13 +11,9 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
/** Various options for describing the viewpoint of a map, along with parameters
|
||||
for transitioning to the viewpoint with animation. All fields are optional;
|
||||
the default values of transition options depend on how this struct is used.
|
||||
*/
|
||||
/** Various options for describing the viewpoint of a map. All fields are
|
||||
optional. */
|
||||
struct CameraOptions {
|
||||
// Viewpoint options
|
||||
|
||||
/** Coordinate at the center of the map. */
|
||||
mapbox::util::optional<LatLng> center;
|
||||
|
||||
@@ -32,9 +28,12 @@ struct CameraOptions {
|
||||
/** Pitch toward the horizon measured in radians, with 0 rad resulting in a
|
||||
two-dimensional map. */
|
||||
mapbox::util::optional<double> pitch;
|
||||
|
||||
// Transition options
|
||||
|
||||
};
|
||||
|
||||
/** Various options for describing a transition between viewpoints with
|
||||
animation. All fields are optional; the default values depend on how this
|
||||
struct is used. */
|
||||
struct AnimationOptions {
|
||||
/** Time to animate to the viewpoint defined herein. */
|
||||
mapbox::util::optional<Duration> duration;
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ class Transform;
|
||||
class PointAnnotation;
|
||||
class ShapeAnnotation;
|
||||
struct CameraOptions;
|
||||
struct AnimationOptions;
|
||||
|
||||
namespace util {
|
||||
template <class T> class Thread;
|
||||
@@ -99,8 +100,8 @@ public:
|
||||
|
||||
// Camera
|
||||
void jumpTo(const CameraOptions&);
|
||||
void easeTo(const CameraOptions&);
|
||||
void flyTo(const CameraOptions&);
|
||||
void easeTo(const CameraOptions&, const AnimationOptions&);
|
||||
void flyTo(const CameraOptions&, const AnimationOptions&);
|
||||
|
||||
// Position
|
||||
void moveBy(const PrecisionPoint&, const Duration& = Duration::zero());
|
||||
|
||||
@@ -1290,19 +1290,19 @@ void JNICALL nativeSetVisibleCoordinateBounds(JNIEnv *env, jobject obj, jlong na
|
||||
segment.push_back(mbgl::LatLng(latitude, longitude));
|
||||
}
|
||||
|
||||
mbgl::CameraOptions options = nativeMapView->getMap().cameraForLatLngs(segment, mbglInsets);
|
||||
|
||||
mbgl::CameraOptions cameraOptions = nativeMapView->getMap().cameraForLatLngs(segment, mbglInsets);
|
||||
if (direction >= 0) {
|
||||
// convert from degrees to radians
|
||||
options.angle = (-direction * M_PI) / 180;
|
||||
cameraOptions.angle = (-direction * M_PI) / 180;
|
||||
}
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
if (duration > 0) {
|
||||
options.duration = std::chrono::milliseconds(duration);
|
||||
animationOptions.duration = std::chrono::milliseconds(duration);
|
||||
// equivalent to kCAMediaTimingFunctionDefault in iOS
|
||||
options.easing = {0.25, 0.1, 0.25, 0.1};
|
||||
animationOptions.easing = {0.25, 0.1, 0.25, 0.1};
|
||||
}
|
||||
|
||||
nativeMapView->getMap().easeTo(options);
|
||||
nativeMapView->getMap().easeTo(cameraOptions, animationOptions);
|
||||
}
|
||||
|
||||
void JNICALL nativeOnLowMemory(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
|
||||
@@ -1528,20 +1528,21 @@ void JNICALL nativeEaseTo(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdou
|
||||
return;
|
||||
}
|
||||
|
||||
mbgl::CameraOptions options;
|
||||
mbgl::CameraOptions cameraOptions;
|
||||
if (angle != -1) {
|
||||
options.angle = angle;
|
||||
cameraOptions.angle = angle;
|
||||
}
|
||||
options.center = mbgl::LatLng(latitude, longitude);
|
||||
options.duration = mbgl::Duration(duration);
|
||||
cameraOptions.center = mbgl::LatLng(latitude, longitude);
|
||||
if (pitch != -1) {
|
||||
options.pitch = pitch;
|
||||
cameraOptions.pitch = pitch;
|
||||
}
|
||||
if (zoom != -1) {
|
||||
options.zoom = zoom;
|
||||
cameraOptions.zoom = zoom;
|
||||
}
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
animationOptions.duration = mbgl::Duration(duration);
|
||||
|
||||
nativeMapView->getMap().easeTo(options);
|
||||
nativeMapView->getMap().easeTo(cameraOptions, animationOptions);
|
||||
}
|
||||
|
||||
void JNICALL nativeFlyTo(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble angle, jobject centerLatLng, jlong duration, jdouble pitch, jdouble zoom) {
|
||||
@@ -1561,20 +1562,21 @@ void JNICALL nativeFlyTo(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdoub
|
||||
return;
|
||||
}
|
||||
|
||||
mbgl::CameraOptions options;
|
||||
mbgl::CameraOptions cameraOptions;
|
||||
if (angle != -1) {
|
||||
options.angle = angle;
|
||||
cameraOptions.angle = angle;
|
||||
}
|
||||
options.center = mbgl::LatLng(latitude, longitude);
|
||||
options.duration = mbgl::Duration(duration);
|
||||
cameraOptions.center = mbgl::LatLng(latitude, longitude);
|
||||
if (pitch != -1) {
|
||||
options.pitch = pitch;
|
||||
cameraOptions.pitch = pitch;
|
||||
}
|
||||
if (zoom != -1) {
|
||||
options.zoom = zoom;
|
||||
cameraOptions.zoom = zoom;
|
||||
}
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
animationOptions.duration = mbgl::Duration(duration);
|
||||
|
||||
nativeMapView->getMap().flyTo(options);
|
||||
nativeMapView->getMap().flyTo(cameraOptions, animationOptions);
|
||||
}
|
||||
|
||||
void JNICALL nativeAddCustomLayer(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jobject customLayer, jstring before) {
|
||||
|
||||
@@ -125,7 +125,7 @@ if [ -z `which jazzy` ]; then
|
||||
step "Installing jazzy..."
|
||||
gem install jazzy
|
||||
if [ -z `which jazzy` ]; then
|
||||
echo "Unable to install jazzy. See https://github.com/mapbox/mapbox-gl-native/blob/master/docs/BUILD_IOS_OSX.md"
|
||||
echo "Unable to install jazzy. See https://github.com/mapbox/mapbox-gl-native/blob/master/platform/ios/INSTALL.md"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -1621,31 +1621,33 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
|
||||
{
|
||||
_mbglMap->cancelTransitions();
|
||||
|
||||
NSTimeInterval duration = animated ? MGLAnimationDuration : 0;
|
||||
mbgl::CameraOptions options;
|
||||
options.center = MGLLatLngFromLocationCoordinate2D(centerCoordinate);
|
||||
options.zoom = fmaxf(zoomLevel, self.currentMinimumZoom);
|
||||
mbgl::CameraOptions cameraOptions;
|
||||
cameraOptions.center = MGLLatLngFromLocationCoordinate2D(centerCoordinate);
|
||||
cameraOptions.zoom = fmaxf(zoomLevel, self.currentMinimumZoom);
|
||||
if (direction >= 0)
|
||||
{
|
||||
options.angle = MGLRadiansFromDegrees(-direction);
|
||||
cameraOptions.angle = MGLRadiansFromDegrees(-direction);
|
||||
}
|
||||
|
||||
NSTimeInterval duration = animated ? MGLAnimationDuration : 0;
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
if (animated)
|
||||
{
|
||||
options.duration = MGLDurationInSeconds(duration);
|
||||
options.easing = MGLUnitBezierForMediaTimingFunction(nil);
|
||||
animationOptions.duration = MGLDurationInSeconds(duration);
|
||||
animationOptions.easing = MGLUnitBezierForMediaTimingFunction(nil);
|
||||
}
|
||||
if (completion)
|
||||
{
|
||||
options.transitionFinishFn = [completion]() {
|
||||
animationOptions.transitionFinishFn = [completion]() {
|
||||
// Must run asynchronously after the transition is completely over.
|
||||
// Otherwise, a call to -setCenterCoordinate: within the completion
|
||||
// handler would reenter the completion handler’s caller.
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completion();
|
||||
});
|
||||
};
|
||||
}
|
||||
_mbglMap->easeTo(options);
|
||||
_mbglMap->easeTo(cameraOptions, animationOptions);
|
||||
|
||||
[self unrotateIfNeededAnimated:animated];
|
||||
}
|
||||
@@ -1734,32 +1736,35 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
|
||||
|
||||
// NOTE: does not disrupt tracking mode
|
||||
[self willChangeValueForKey:@"visibleCoordinateBounds"];
|
||||
mbgl::EdgeInsets mbglInsets = {insets.top, insets.left, insets.bottom, insets.right};
|
||||
mbgl::EdgeInsets mbglInsets = MGLEdgeInsetsFromNSEdgeInsets(insets);
|
||||
mbgl::AnnotationSegment segment;
|
||||
segment.reserve(count);
|
||||
for (NSUInteger i = 0; i < count; i++)
|
||||
{
|
||||
segment.push_back({coordinates[i].latitude, coordinates[i].longitude});
|
||||
}
|
||||
mbgl::CameraOptions options = _mbglMap->cameraForLatLngs(segment, mbglInsets);
|
||||
|
||||
mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngs(segment, mbglInsets);
|
||||
if (direction >= 0)
|
||||
{
|
||||
options.angle = MGLRadiansFromDegrees(-direction);
|
||||
cameraOptions.angle = MGLRadiansFromDegrees(-direction);
|
||||
}
|
||||
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
if (duration > 0)
|
||||
{
|
||||
options.duration = MGLDurationInSeconds(duration);
|
||||
options.easing = MGLUnitBezierForMediaTimingFunction(function);
|
||||
animationOptions.duration = MGLDurationInSeconds(duration);
|
||||
animationOptions.easing = MGLUnitBezierForMediaTimingFunction(function);
|
||||
}
|
||||
if (completion)
|
||||
{
|
||||
options.transitionFinishFn = [completion]() {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
animationOptions.transitionFinishFn = [completion]() {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completion();
|
||||
});
|
||||
};
|
||||
}
|
||||
_mbglMap->easeTo(options);
|
||||
_mbglMap->easeTo(cameraOptions, animationOptions);
|
||||
[self didChangeValueForKey:@"visibleCoordinateBounds"];
|
||||
|
||||
[self unrotateIfNeededAnimated:duration > 0];
|
||||
@@ -1848,23 +1853,24 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
|
||||
return;
|
||||
}
|
||||
|
||||
mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
|
||||
mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera];
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
if (duration > 0)
|
||||
{
|
||||
options.duration = MGLDurationInSeconds(duration);
|
||||
options.easing = MGLUnitBezierForMediaTimingFunction(function);
|
||||
animationOptions.duration = MGLDurationInSeconds(duration);
|
||||
animationOptions.easing = MGLUnitBezierForMediaTimingFunction(function);
|
||||
}
|
||||
if (completion)
|
||||
{
|
||||
options.transitionFinishFn = [completion]() {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
animationOptions.transitionFinishFn = [completion]() {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completion();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
[self willChangeValueForKey:@"camera"];
|
||||
_mbglMap->easeTo(options);
|
||||
_mbglMap->easeTo(cameraOptions, animationOptions);
|
||||
[self didChangeValueForKey:@"camera"];
|
||||
}
|
||||
|
||||
@@ -1886,29 +1892,30 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
|
||||
return;
|
||||
}
|
||||
|
||||
mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
|
||||
mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera];
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
if (duration >= 0)
|
||||
{
|
||||
options.duration = MGLDurationInSeconds(duration);
|
||||
animationOptions.duration = MGLDurationInSeconds(duration);
|
||||
}
|
||||
if (peakAltitude >= 0)
|
||||
{
|
||||
CLLocationDegrees peakLatitude = (self.centerCoordinate.latitude + camera.centerCoordinate.latitude) / 2;
|
||||
CLLocationDegrees peakPitch = (self.camera.pitch + camera.pitch) / 2;
|
||||
options.minZoom = MGLZoomLevelForAltitude(peakAltitude, peakPitch,
|
||||
peakLatitude, self.frame.size);
|
||||
animationOptions.minZoom = MGLZoomLevelForAltitude(peakAltitude, peakPitch,
|
||||
peakLatitude, self.frame.size);
|
||||
}
|
||||
if (completion)
|
||||
{
|
||||
options.transitionFinishFn = [completion]() {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
animationOptions.transitionFinishFn = [completion]() {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completion();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
[self willChangeValueForKey:@"camera"];
|
||||
_mbglMap->flyTo(options);
|
||||
_mbglMap->flyTo(cameraOptions, animationOptions);
|
||||
[self didChangeValueForKey:@"camera"];
|
||||
}
|
||||
|
||||
|
||||
@@ -954,24 +954,25 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
|
||||
mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera];
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
if (duration > 0) {
|
||||
options.duration = MGLDurationInSeconds(duration);
|
||||
options.easing = MGLUnitBezierForMediaTimingFunction(function);
|
||||
animationOptions.duration = MGLDurationInSeconds(duration);
|
||||
animationOptions.easing = MGLUnitBezierForMediaTimingFunction(function);
|
||||
}
|
||||
if (completion) {
|
||||
options.transitionFinishFn = [completion]() {
|
||||
animationOptions.transitionFinishFn = [completion]() {
|
||||
// Must run asynchronously after the transition is completely over.
|
||||
// Otherwise, a call to -setCamera: within the completion handler
|
||||
// would reenter the completion handler’s caller.
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completion();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
[self willChangeValueForKey:@"camera"];
|
||||
_mbglMap->easeTo(options);
|
||||
_mbglMap->easeTo(cameraOptions, animationOptions);
|
||||
[self didChangeValueForKey:@"camera"];
|
||||
}
|
||||
|
||||
@@ -989,29 +990,30 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
|
||||
mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera];
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
if (duration >= 0) {
|
||||
options.duration = MGLDurationInSeconds(duration);
|
||||
animationOptions.duration = MGLDurationInSeconds(duration);
|
||||
}
|
||||
if (peakAltitude >= 0) {
|
||||
CLLocationDegrees peakLatitude = (self.centerCoordinate.latitude + camera.centerCoordinate.latitude) / 2;
|
||||
CLLocationDegrees peakPitch = (self.camera.pitch + camera.pitch) / 2;
|
||||
options.minZoom = MGLZoomLevelForAltitude(peakAltitude, peakPitch,
|
||||
peakLatitude, self.frame.size);
|
||||
animationOptions.minZoom = MGLZoomLevelForAltitude(peakAltitude, peakPitch,
|
||||
peakLatitude, self.frame.size);
|
||||
}
|
||||
if (completion) {
|
||||
options.transitionFinishFn = [completion]() {
|
||||
animationOptions.transitionFinishFn = [completion]() {
|
||||
// Must run asynchronously after the transition is completely over.
|
||||
// Otherwise, a call to -setCamera: within the completion handler
|
||||
// would reenter the completion handler’s caller.
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completion();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
[self willChangeValueForKey:@"camera"];
|
||||
_mbglMap->flyTo(options);
|
||||
_mbglMap->flyTo(cameraOptions, animationOptions);
|
||||
[self didChangeValueForKey:@"camera"];
|
||||
}
|
||||
|
||||
@@ -1052,16 +1054,17 @@ public:
|
||||
_mbglMap->cancelTransitions();
|
||||
|
||||
mbgl::EdgeInsets mbglInsets = MGLEdgeInsetsFromNSEdgeInsets(insets);
|
||||
mbgl::CameraOptions options = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), mbglInsets);
|
||||
mbgl::CameraOptions cameraOptions = _mbglMap->cameraForLatLngBounds(MGLLatLngBoundsFromCoordinateBounds(bounds), mbglInsets);
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
if (animated) {
|
||||
options.duration = MGLDurationInSeconds(MGLAnimationDuration);
|
||||
animationOptions.duration = MGLDurationInSeconds(MGLAnimationDuration);
|
||||
}
|
||||
|
||||
[self willChangeValueForKey:@"visibleCoordinateBounds"];
|
||||
options.transitionFinishFn = ^() {
|
||||
animationOptions.transitionFinishFn = ^() {
|
||||
[self didChangeValueForKey:@"visibleCoordinateBounds"];
|
||||
};
|
||||
_mbglMap->easeTo(options);
|
||||
_mbglMap->easeTo(cameraOptions, animationOptions);
|
||||
}
|
||||
|
||||
#pragma mark Mouse events and gestures
|
||||
|
||||
@@ -148,20 +148,20 @@ bool Map::isPanning() const {
|
||||
|
||||
#pragma mark -
|
||||
|
||||
void Map::jumpTo(const CameraOptions& options) {
|
||||
transform->jumpTo(options);
|
||||
update(options.zoom ? Update::Zoom : Update::Repaint);
|
||||
void Map::jumpTo(const CameraOptions& camera) {
|
||||
transform->jumpTo(camera);
|
||||
update(camera.zoom ? Update::Zoom : Update::Repaint);
|
||||
}
|
||||
|
||||
void Map::easeTo(const CameraOptions& options) {
|
||||
transform->easeTo(options);
|
||||
update(options.zoom ? Update::Zoom : Update::Repaint);
|
||||
void Map::easeTo(const CameraOptions& camera, const AnimationOptions& animation) {
|
||||
transform->easeTo(camera, animation);
|
||||
update(camera.zoom ? Update::Zoom : Update::Repaint);
|
||||
}
|
||||
|
||||
|
||||
void Map::flyTo(const CameraOptions& options) {
|
||||
transform->flyTo(options);
|
||||
update(options.zoom ? Update::Zoom : Update::Repaint);
|
||||
void Map::flyTo(const CameraOptions& camera, const AnimationOptions& animation) {
|
||||
transform->flyTo(camera, animation);
|
||||
update(Update::Zoom);
|
||||
}
|
||||
|
||||
#pragma mark - Position
|
||||
|
||||
@@ -67,10 +67,8 @@ bool Transform::resize(const std::array<uint16_t, 2> size) {
|
||||
* a transition. The map will retain the current values for any options
|
||||
* not included in `options`.
|
||||
*/
|
||||
void Transform::jumpTo(const CameraOptions& options) {
|
||||
CameraOptions jumpOptions(options);
|
||||
jumpOptions.duration.reset();
|
||||
easeTo(jumpOptions);
|
||||
void Transform::jumpTo(const CameraOptions& camera) {
|
||||
easeTo(camera, {});
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -78,11 +76,11 @@ void Transform::jumpTo(const CameraOptions& options) {
|
||||
* between old and new values. The map will retain the current values for any options
|
||||
* not included in `options`.
|
||||
*/
|
||||
void Transform::easeTo(const CameraOptions& options) {
|
||||
CameraOptions easeOptions(options);
|
||||
LatLng latLng = easeOptions.center ? *easeOptions.center : getLatLng();
|
||||
double zoom = easeOptions.zoom ? *easeOptions.zoom : getZoom();
|
||||
double angle = easeOptions.angle ? *easeOptions.angle : getAngle();
|
||||
void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& animation) {
|
||||
CameraOptions easeCamera(camera);
|
||||
LatLng latLng = easeCamera.center ? *easeCamera.center : getLatLng();
|
||||
double zoom = easeCamera.zoom ? *easeCamera.zoom : getZoom();
|
||||
double angle = easeCamera.angle ? *easeCamera.angle : getAngle();
|
||||
if (!latLng || std::isnan(zoom) || std::isnan(angle)) {
|
||||
return;
|
||||
}
|
||||
@@ -99,10 +97,10 @@ void Transform::easeTo(const CameraOptions& options) {
|
||||
double xn = -latLng.longitude * state.Bc;
|
||||
double yn = 0.5 * state.Cc * std::log((1 + f) / (1 - f));
|
||||
|
||||
easeOptions.center.reset();
|
||||
easeOptions.zoom.reset();
|
||||
easeOptions.angle.reset();
|
||||
_easeTo(easeOptions, new_scale, angle, xn, yn);
|
||||
easeCamera.center.reset();
|
||||
easeCamera.zoom.reset();
|
||||
easeCamera.angle.reset();
|
||||
_easeTo(easeCamera, animation, new_scale, angle, xn, yn);
|
||||
}
|
||||
|
||||
void Transform::moveBy(const PrecisionPoint& point, const Duration& duration) {
|
||||
@@ -119,9 +117,9 @@ void Transform::_moveBy(const PrecisionPoint& point, const Duration& duration) {
|
||||
|
||||
state.constrain(state.scale, x, y);
|
||||
|
||||
CameraOptions options;
|
||||
options.duration = duration;
|
||||
_easeTo(options, state.scale, state.angle, x, y);
|
||||
AnimationOptions animation;
|
||||
animation.duration = duration;
|
||||
_easeTo({}, animation, state.scale, state.angle, x, y);
|
||||
}
|
||||
|
||||
void Transform::setLatLng(const LatLng& latLng, const Duration& duration) {
|
||||
@@ -129,10 +127,11 @@ void Transform::setLatLng(const LatLng& latLng, const Duration& duration) {
|
||||
return;
|
||||
}
|
||||
|
||||
CameraOptions options;
|
||||
options.center = latLng;
|
||||
options.duration = duration;
|
||||
easeTo(options);
|
||||
CameraOptions camera;
|
||||
camera.center = latLng;
|
||||
AnimationOptions animation;
|
||||
animation.duration = duration;
|
||||
easeTo(camera, animation);
|
||||
}
|
||||
|
||||
void Transform::setLatLng(const LatLng& latLng, const PrecisionPoint& point, const Duration& duration) {
|
||||
@@ -161,11 +160,12 @@ void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const Duration&
|
||||
return;
|
||||
}
|
||||
|
||||
CameraOptions options;
|
||||
options.center = latLng;
|
||||
options.zoom = zoom;
|
||||
options.duration = duration;
|
||||
easeTo(options);
|
||||
CameraOptions camera;
|
||||
camera.center = latLng;
|
||||
camera.zoom = zoom;
|
||||
AnimationOptions animation;
|
||||
animation.duration = duration;
|
||||
easeTo(camera, animation);
|
||||
}
|
||||
|
||||
|
||||
@@ -227,18 +227,13 @@ void Transform::_setScale(double new_scale, const PrecisionPoint& center, const
|
||||
const double xn = state.x * factor - dx;
|
||||
const double yn = state.y * factor - dy;
|
||||
|
||||
_setScaleXY(new_scale, xn, yn, duration);
|
||||
AnimationOptions animation;
|
||||
animation.duration = duration;
|
||||
_easeTo({}, animation, new_scale, state.angle, xn, yn);
|
||||
}
|
||||
|
||||
void Transform::_setScaleXY(double new_scale, double xn, double yn,
|
||||
const Duration& duration) {
|
||||
CameraOptions options;
|
||||
options.duration = duration;
|
||||
_easeTo(options, new_scale, state.angle, xn, yn);
|
||||
}
|
||||
|
||||
void Transform::_easeTo(const CameraOptions& options, double new_scale, double new_angle, double xn, double yn) {
|
||||
CameraOptions easeOptions(options);
|
||||
void Transform::_easeTo(const CameraOptions& camera, const AnimationOptions& animation,
|
||||
double new_scale, double new_angle, double xn, double yn) {
|
||||
Update update = state.scale == new_scale ? Update::Repaint : Update::Zoom;
|
||||
double scale = new_scale;
|
||||
double x = xn;
|
||||
@@ -248,13 +243,11 @@ void Transform::_easeTo(const CameraOptions& options, double new_scale, double n
|
||||
|
||||
double angle = _normalizeAngle(new_angle, state.angle);
|
||||
state.angle = _normalizeAngle(state.angle, angle);
|
||||
double pitch = easeOptions.pitch ? *easeOptions.pitch : state.pitch;
|
||||
double pitch = camera.pitch ? *camera.pitch : state.pitch;
|
||||
pitch = util::clamp(pitch, 0., util::PITCH_MAX);
|
||||
|
||||
if (!easeOptions.duration) {
|
||||
easeOptions.duration = Duration::zero();
|
||||
}
|
||||
if (!easeOptions.duration || *easeOptions.duration == Duration::zero()) {
|
||||
Duration duration = animation.duration ? *animation.duration : Duration::zero();
|
||||
if (duration == Duration::zero()) {
|
||||
view.notifyMapChange(MapChangeRegionWillChange);
|
||||
|
||||
state.scale = scale;
|
||||
@@ -267,8 +260,8 @@ void Transform::_easeTo(const CameraOptions& options, double new_scale, double n
|
||||
state.angle = angle;
|
||||
state.pitch = pitch;
|
||||
|
||||
if (options.transitionFinishFn) {
|
||||
options.transitionFinishFn();
|
||||
if (animation.transitionFinishFn) {
|
||||
animation.transitionFinishFn();
|
||||
}
|
||||
view.notifyMapChange(MapChangeRegionDidChange);
|
||||
} else {
|
||||
@@ -285,7 +278,7 @@ void Transform::_easeTo(const CameraOptions& options, double new_scale, double n
|
||||
|
||||
startTransition(
|
||||
[=](double t) {
|
||||
util::UnitBezier ease = easeOptions.easing ? *easeOptions.easing : util::UnitBezier(0, 0, 0.25, 1);
|
||||
util::UnitBezier ease = animation.easing ? *animation.easing : util::UnitBezier(0, 0, 0.25, 1);
|
||||
return ease.solve(t, 0.001);
|
||||
},
|
||||
[=](double t) {
|
||||
@@ -299,8 +292,8 @@ void Transform::_easeTo(const CameraOptions& options, double new_scale, double n
|
||||
state.pitch = util::interpolate(startP, pitch, t);
|
||||
// At t = 1.0, a DidChangeAnimated notification should be sent from finish().
|
||||
if (t < 1.0) {
|
||||
if (options.transitionFrameFn) {
|
||||
options.transitionFrameFn(t);
|
||||
if (animation.transitionFrameFn) {
|
||||
animation.transitionFrameFn(t);
|
||||
}
|
||||
view.notifyMapChange(MapChangeRegionIsChanging);
|
||||
}
|
||||
@@ -310,11 +303,11 @@ void Transform::_easeTo(const CameraOptions& options, double new_scale, double n
|
||||
state.panning = false;
|
||||
state.scaling = false;
|
||||
state.rotating = false;
|
||||
if (options.transitionFinishFn) {
|
||||
options.transitionFinishFn();
|
||||
if (animation.transitionFinishFn) {
|
||||
animation.transitionFinishFn();
|
||||
}
|
||||
view.notifyMapChange(MapChangeRegionDidChangeAnimated);
|
||||
}, *easeOptions.duration);
|
||||
}, duration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,13 +319,12 @@ void Transform::_easeTo(const CameraOptions& options, double new_scale, double n
|
||||
|
||||
Where applicable, local variable documentation begins with the associated
|
||||
variable or function in van Wijk (2003). */
|
||||
void Transform::flyTo(const CameraOptions &options) {
|
||||
CameraOptions flyOptions(options);
|
||||
LatLng latLng = options.center ? *options.center : getLatLng();
|
||||
void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &animation) {
|
||||
LatLng latLng = camera.center ? *camera.center : getLatLng();
|
||||
LatLng startLatLng = getLatLng();
|
||||
double zoom = flyOptions.zoom ? *flyOptions.zoom : getZoom();
|
||||
double angle = flyOptions.angle ? *flyOptions.angle : getAngle();
|
||||
double pitch = flyOptions.pitch ? *flyOptions.pitch : getPitch();
|
||||
double zoom = camera.zoom ? *camera.zoom : getZoom();
|
||||
double angle = camera.angle ? *camera.angle : getAngle();
|
||||
double pitch = camera.pitch ? *camera.pitch : getPitch();
|
||||
|
||||
if (std::isnan(latLng.latitude) || std::isnan(latLng.longitude) || std::isnan(zoom)) {
|
||||
return;
|
||||
@@ -388,8 +380,8 @@ void Transform::flyTo(const CameraOptions &options) {
|
||||
root mean squared average velocity, V<sub>RMS</sub>. A value of 1 would
|
||||
produce a circular motion. */
|
||||
double rho = 1.42;
|
||||
if (flyOptions.minZoom) {
|
||||
double minZoom = util::min(*flyOptions.minZoom, startZoom, zoom);
|
||||
if (animation.minZoom) {
|
||||
double minZoom = util::min(*animation.minZoom, startZoom, zoom);
|
||||
minZoom = util::clamp(minZoom, state.getMinZoom(), state.getMaxZoom());
|
||||
/// w<sub>m</sub>: Maximum visible span, measured in pixels with respect
|
||||
/// to the initial scale.
|
||||
@@ -412,7 +404,7 @@ void Transform::flyTo(const CameraOptions &options) {
|
||||
bool isClose = std::abs(u1) < 0.000001;
|
||||
// Perform a more or less instantaneous transition if the path is too short.
|
||||
if (isClose && std::abs(w0 - w1) < 0.000001) {
|
||||
easeTo(options);
|
||||
easeTo(camera, animation);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -438,20 +430,20 @@ void Transform::flyTo(const CameraOptions &options) {
|
||||
: ((r(1) - r0) / rho));
|
||||
|
||||
Duration duration;
|
||||
if (flyOptions.duration) {
|
||||
duration = *flyOptions.duration;
|
||||
if (animation.duration) {
|
||||
duration = *animation.duration;
|
||||
} else {
|
||||
/// V: Average velocity, measured in ρ-screenfuls per second.
|
||||
double velocity = 1.2;
|
||||
if (flyOptions.velocity) {
|
||||
velocity = *flyOptions.velocity / rho;
|
||||
if (animation.velocity) {
|
||||
velocity = *animation.velocity / rho;
|
||||
}
|
||||
duration = std::chrono::duration_cast<std::chrono::steady_clock::duration>(
|
||||
std::chrono::duration<double, std::chrono::seconds::period>(S / velocity));
|
||||
}
|
||||
if (duration == Duration::zero()) {
|
||||
// Perform an instantaneous transition.
|
||||
jumpTo(options);
|
||||
jumpTo(camera);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -467,7 +459,7 @@ void Transform::flyTo(const CameraOptions &options) {
|
||||
|
||||
startTransition(
|
||||
[=](double t) {
|
||||
util::UnitBezier ease = flyOptions.easing ? *flyOptions.easing : util::UnitBezier(0, 0, 0.25, 1);
|
||||
util::UnitBezier ease = animation.easing ? *animation.easing : util::UnitBezier(0, 0, 0.25, 1);
|
||||
return ease.solve(t, 0.001);
|
||||
},
|
||||
[=](double k) {
|
||||
@@ -496,8 +488,8 @@ void Transform::flyTo(const CameraOptions &options) {
|
||||
|
||||
// At k = 1.0, a DidChangeAnimated notification should be sent from finish().
|
||||
if (k < 1.0) {
|
||||
if (options.transitionFrameFn) {
|
||||
options.transitionFrameFn(k);
|
||||
if (animation.transitionFrameFn) {
|
||||
animation.transitionFrameFn(k);
|
||||
}
|
||||
view.notifyMapChange(MapChangeRegionIsChanging);
|
||||
}
|
||||
@@ -507,8 +499,8 @@ void Transform::flyTo(const CameraOptions &options) {
|
||||
state.panning = false;
|
||||
state.scaling = false;
|
||||
state.rotating = false;
|
||||
if (options.transitionFinishFn) {
|
||||
options.transitionFinishFn();
|
||||
if (animation.transitionFinishFn) {
|
||||
animation.transitionFinishFn();
|
||||
}
|
||||
view.notifyMapChange(MapChangeRegionDidChangeAnimated);
|
||||
}, duration);
|
||||
@@ -571,10 +563,11 @@ void Transform::setAngle(double new_angle, const PrecisionPoint& center) {
|
||||
}
|
||||
|
||||
void Transform::_setAngle(double new_angle, const Duration& duration) {
|
||||
CameraOptions options;
|
||||
options.angle = new_angle;
|
||||
options.duration = duration;
|
||||
easeTo(options);
|
||||
CameraOptions camera;
|
||||
camera.angle = new_angle;
|
||||
AnimationOptions animation;
|
||||
animation.duration = duration;
|
||||
easeTo(camera, animation);
|
||||
}
|
||||
|
||||
double Transform::getAngle() const {
|
||||
@@ -588,10 +581,11 @@ void Transform::setPitch(double pitch, const Duration& duration) {
|
||||
return;
|
||||
}
|
||||
|
||||
CameraOptions options;
|
||||
options.pitch = pitch;
|
||||
options.duration = duration;
|
||||
easeTo(options);
|
||||
CameraOptions camera;
|
||||
camera.pitch = pitch;
|
||||
AnimationOptions animation;
|
||||
animation.duration = duration;
|
||||
easeTo(camera, animation);
|
||||
}
|
||||
|
||||
double Transform::getPitch() const {
|
||||
|
||||
@@ -25,10 +25,10 @@ public:
|
||||
bool resize(std::array<uint16_t, 2> size);
|
||||
|
||||
void jumpTo(const CameraOptions&);
|
||||
void easeTo(const CameraOptions&);
|
||||
void easeTo(const CameraOptions&, const AnimationOptions&);
|
||||
/** Smoothly zoom out, pan, and zoom back into the given camera along a
|
||||
great circle, as though the viewer is aboard a supersonic jetcopter. */
|
||||
void flyTo(const CameraOptions&);
|
||||
void flyTo(const CameraOptions&, const AnimationOptions&);
|
||||
|
||||
// Position
|
||||
void moveBy(const PrecisionPoint&, const Duration& = Duration::zero());
|
||||
@@ -76,8 +76,7 @@ public:
|
||||
private:
|
||||
void _moveBy(const PrecisionPoint&, const Duration& = Duration::zero());
|
||||
void _setScale(double scale, const PrecisionPoint& center, const Duration& = Duration::zero());
|
||||
void _setScaleXY(double new_scale, double xn, double yn, const Duration& = Duration::zero());
|
||||
void _easeTo(const CameraOptions&, double new_scale, double new_angle, double xn, double yn);
|
||||
void _easeTo(const CameraOptions&, const AnimationOptions&, double new_scale, double new_angle, double xn, double yn);
|
||||
void _setAngle(double angle, const Duration& = Duration::zero());
|
||||
|
||||
View &view;
|
||||
|
||||
Reference in New Issue
Block a user