Skip to content

Commit 4c31a52

Browse files
Add configurable threshold for rotate gesture snapping to north (#3914)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 76da093 commit 4c31a52

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

platform/ios/src/MLNMapView.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,15 @@ vertically on the map.
855855
*/
856856
@property (nonatomic, getter=isRotateEnabled) BOOL rotateEnabled;
857857

858+
/**
859+
The threshold, measured in degrees, that determines when the map's bearing will snap to north.
860+
For example, with a toleranceForSnappingToNorth of 7, if the user rotates the map within 7 degrees
861+
of north, the map will automatically snap to exact north.
862+
863+
The default value of this property is 7.
864+
*/
865+
@property (nonatomic) CGFloat toleranceForSnappingToNorth;
866+
858867
/**
859868
A Boolean value that determines whether the user may change the pitch (tilt) of
860869
the map.

platform/ios/src/MLNMapView.mm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@ typedef NS_ENUM(NSUInteger, MLNUserTrackingState) {
290290
/// Initial zoom level when entering user tracking mode from a low zoom level.
291291
const double MLNDefaultZoomLevelForUserTracking = 14.0;
292292

293-
/// Tolerance for snapping to true north, measured in degrees in either direction.
294-
const CLLocationDirection MLNToleranceForSnappingToNorth = 7;
295-
296293
/// Distance threshold to stop the camera while animating.
297294
const CLLocationDistance MLNDistanceThresholdForCameraPause = 500;
298295

@@ -883,6 +880,7 @@ - (void)commonInitWithOptions:(MLNMapOptions*)mlnMapoptions
883880
[self addGestureRecognizer:_rotate];
884881
_rotateEnabled = YES;
885882
_rotationThresholdWhileZooming = 3;
883+
_toleranceForSnappingToNorth = 7;
886884

887885
_doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapGesture:)];
888886
_doubleTap.numberOfTapsRequired = 2;
@@ -6839,8 +6837,8 @@ - (void)unrotateIfNeededForGesture
68396837
[self unrotateIfNeededAnimated:YES];
68406838

68416839
// Snap to north.
6842-
if ((self.direction < MLNToleranceForSnappingToNorth
6843-
|| self.direction > 360 - MLNToleranceForSnappingToNorth)
6840+
if ((self.direction < self.toleranceForSnappingToNorth
6841+
|| self.direction > 360 - self.toleranceForSnappingToNorth)
68446842
&& self.userTrackingMode != MLNUserTrackingModeFollowWithHeading
68456843
&& self.userTrackingMode != MLNUserTrackingModeFollowWithCourse)
68466844
{

0 commit comments

Comments
 (0)