From c444318ccf8410e08e8c617aab8ff3028a54fe27 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Thu, 2 May 2019 15:44:38 -0700 Subject: [ios] Fix excessive cpu usage. --- platform/ios/src/MGLMapView.mm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 7cebd57710..17c92c8a7d 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -108,6 +108,8 @@ typedef NS_ENUM(NSUInteger, MGLUserTrackingState) { MGLUserTrackingStateBeginSignificantTransition, /// The map view has finished moving to the first reported user location. MGLUserTrackingStateChanged, + + MGLUserTrackingStateThreshold, }; const NSTimeInterval MGLAnimationDuration = 0.3; @@ -5700,6 +5702,15 @@ public: { return; } + + CGPoint threshold = CGPointMake(20, 20); + if (self.userTrackingState != MGLUserTrackingStatePossible + && std::abs(currentPoint.x - correctPoint.x) <= threshold.x && std::abs(currentPoint.y - correctPoint.y) <= threshold.y + && self.userTrackingMode != MGLUserTrackingModeFollowWithCourse) + { + self.userTrackingState = MGLUserTrackingStateThreshold; + return; + } if (self.userTrackingMode == MGLUserTrackingModeFollowWithCourse && CLLocationCoordinate2DIsValid(self.targetCoordinate)) @@ -6549,6 +6560,9 @@ public: { userPoint = MGLPointRounded([self convertCoordinate:self.userLocation.coordinate toPointToView:self]); } + if (self.userTrackingState == MGLUserTrackingStateThreshold) { + self.userTrackingState = MGLUserTrackingStateChanged; + } if ( ! annotationView.superview) { -- cgit v1.2.1