diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 84af449fa..1112ac6c9 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -130,6 +130,7 @@ public: // Pitch void setPitch(double pitch, const Duration& = Duration::zero()); + void setPitch(double pitch, const PrecisionPoint&, const Duration& = Duration::zero()); double getPitch() const; // North Orientation diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index cc25ec4da..cd013e451 100644 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -680,11 +680,12 @@ jdouble JNICALL nativeGetPitch(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) return nativeMapView->getMap().getPitch(); } -void JNICALL nativeSetPitch(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble pitch, jlong duration) { +void JNICALL nativeSetPitch(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble pitch, jlong milliseconds) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeGetPitch"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - nativeMapView->getMap().setPitch(pitch, mbgl::Milliseconds(duration)); + mbgl::Duration duration((mbgl::Milliseconds(milliseconds))); + nativeMapView->getMap().setPitch(pitch, duration); } void JNICALL nativeScaleBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble ds, jdouble cx, diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index d499dc747..1952597a4 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1428,8 +1428,13 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) CGFloat slowdown = 20.0; CGFloat pitchNew = currentPitch - (gestureDistance / slowdown); - - _mbglMap->setPitch(pitchNew); + + CGPoint centerPoint = self.contentCenter; + if (self.userTrackingMode != MGLUserTrackingModeNone) + { + centerPoint = self.userLocationAnnotationViewCenter; + } + _mbglMap->setPitch(pitchNew, centerPoint); [self notifyMapChange:mbgl::MapChangeRegionIsChanging]; } diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm index 3bea3f113..fe95427e5 100644 --- a/platform/osx/src/MGLMapView.mm +++ b/platform/osx/src/MGLMapView.mm @@ -1207,7 +1207,7 @@ public: [self didChangeValueForKey:@"direction"]; } if (self.pitchEnabled) { - _mbglMap->setPitch(_pitchAtBeginningOfGesture + delta.y / 5); + _mbglMap->setPitch(_pitchAtBeginningOfGesture + delta.y / 5, center); } } } else if (self.scrollEnabled) { diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 51106db88..a45a9ffaf 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -357,7 +357,11 @@ void Map::resetNorth(const Duration& duration) { #pragma mark - Pitch void Map::setPitch(double pitch, const Duration& duration) { - transform->setPitch(pitch * M_PI / 180, duration); + setPitch(pitch, {NAN, NAN}, duration); +} + +void Map::setPitch(double pitch, const PrecisionPoint& anchor, const Duration& duration) { + transform->setPitch(pitch * M_PI / 180, anchor, duration); update(Update::Repaint); } diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index b4743c071..208f9a089 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -523,12 +523,17 @@ double Transform::getAngle() const { #pragma mark - Pitch void Transform::setPitch(double pitch, const Duration& duration) { + setPitch(pitch, {NAN, NAN}, duration); +} + +void Transform::setPitch(double pitch, const PrecisionPoint& anchor, const Duration& duration) { if (std::isnan(pitch)) { return; } CameraOptions camera; camera.pitch = pitch; + camera.anchor = anchor; easeTo(camera, duration); } diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index bef6c6c87..8c9ea0888 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -102,7 +102,15 @@ public: double getAngle() const; // Pitch + /** Sets the pitch angle. + @param angle The new pitch angle, measured in radians toward the + horizon. */ void setPitch(double pitch, const Duration& = Duration::zero()); + /** Sets the pitch angle, keeping the given point fixed within the view. + @param angle The new pitch angle, measured in radians toward the + horizon. + @param anchor A point relative to the top-left corner of the view. */ + void setPitch(double pitch, const PrecisionPoint& anchor, const Duration& = Duration::zero()); double getPitch() const; // North Orientation