diff --git a/platform/ios/platform/ios/src/MGLMapView.h b/platform/ios/platform/ios/src/MGLMapView.h index f2eb51dd1..9a88b56e6 100644 --- a/platform/ios/platform/ios/src/MGLMapView.h +++ b/platform/ios/platform/ios/src/MGLMapView.h @@ -733,6 +733,12 @@ MGL_EXPORT */ @property(nonatomic, getter=isPitchEnabled) BOOL pitchEnabled; +/** + A Boolean value that determines whether gestures are anchored to the center coordinate of the map while rotating or zooming. + Default value is set to NO. + */ +@property(nonatomic) BOOL anchorRotateOrZoomGesturesToCenterCoordinate; + /** A Boolean value that determines whether the user will receive haptic feedback for certain interactions with the map. diff --git a/platform/ios/platform/ios/src/MGLMapView.mm b/platform/ios/platform/ios/src/MGLMapView.mm index 58732c302..5c2d75daf 100644 --- a/platform/ios/platform/ios/src/MGLMapView.mm +++ b/platform/ios/platform/ios/src/MGLMapView.mm @@ -581,6 +581,9 @@ public: // setup interaction // + + self.anchorRotateOrZoomGesturesToCenterCoordinate = NO; + _pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)]; _pan.delegate = self; _pan.maximumNumberOfTouches = 1; @@ -1829,6 +1832,11 @@ public: [self cancelTransitions]; CGPoint centerPoint = [self anchorPointForGesture:pinch]; + if (self.anchorRotateOrZoomGesturesToCenterCoordinate) { + if (pinch.numberOfTouches != 1 || pinch.state == UIGestureRecognizerStateEnded) { + centerPoint = [self contentCenter]; + } + } MGLMapCamera *oldCamera = self.camera; self.cameraChangeReasonBitmask |= MGLCameraChangeReasonGesturePinch; @@ -1937,6 +1945,9 @@ public: [self cancelTransitions]; CGPoint centerPoint = [self anchorPointForGesture:rotate]; + if (self.anchorRotateOrZoomGesturesToCenterCoordinate) { + centerPoint = [self contentCenter]; + } MGLMapCamera *oldCamera = self.camera; self.cameraChangeReasonBitmask |= MGLCameraChangeReasonGestureRotate; @@ -1947,6 +1958,9 @@ public: // Check whether a zoom triggered by a pinch gesture is occurring and if the rotation threshold has been met. if (MGLDegreesFromRadians(self.rotationBeforeThresholdMet) < self.rotationThresholdWhileZooming && self.isZooming && !self.isRotating) { self.rotationBeforeThresholdMet += fabs(rotate.rotation); + if (self.anchorRotateOrZoomGesturesToCenterCoordinate) { + self.rotationBeforeThresholdMet = 0; + } rotate.rotation = 0; return; } @@ -2472,6 +2486,14 @@ public: } } } + else if (gestureRecognizer == _pan) + { + if (self.anchorRotateOrZoomGesturesToCenterCoordinate) { + if (self.isZooming || self.isRotating) { + return NO; + } + } + } return YES; }