From a41da826d0224ddd721a225cddb8301e43a0936c Mon Sep 17 00:00:00 2001 From: Evgenii Khrushchev Date: Mon, 5 May 2025 13:54:06 +0200 Subject: [PATCH] Fix: follow with heading tracking mode cancels user location indicator update (#3401) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bart Louwers --- platform/ios/src/MLNMapView.mm | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/platform/ios/src/MLNMapView.mm b/platform/ios/src/MLNMapView.mm index 29c325339..4e3083854 100644 --- a/platform/ios/src/MLNMapView.mm +++ b/platform/ios/src/MLNMapView.mm @@ -4098,10 +4098,10 @@ static void *windowScreenContext = &windowScreenContext; self.userTrackingMode = MLNUserTrackingModeFollow; } - [self _setDirection:direction animated:animated]; + [self _setDirection:direction center:kCLLocationCoordinate2DInvalid animated:animated]; } -- (void)_setDirection:(CLLocationDirection)direction animated:(BOOL)animated +- (void)_setDirection:(CLLocationDirection)direction center:(CLLocationCoordinate2D)center animated:(BOOL)animated { if (!_mbglMap) { @@ -4123,10 +4123,26 @@ static void *windowScreenContext = &windowScreenContext; else { CGPoint anchor = self.userLocationAnnotationViewCenter; - self.mbglMap.easeTo(mbgl::CameraOptions() - .withBearing(direction) - .withAnchor(mbgl::ScreenCoordinate { anchor.x, anchor.y }), - MLNDurationFromTimeInterval(duration)); + + mbgl::CameraOptions cameraOptions = mbgl::CameraOptions() + .withBearing(direction) + .withAnchor(mbgl::ScreenCoordinate { anchor.x, anchor.y }); + + mbgl::AnimationOptions animationOptions; + animationOptions.duration.emplace(MLNDurationFromTimeInterval(duration)); + + if (CLLocationCoordinate2DIsValid(center)) + { + cameraOptions.center = MLNLatLngFromLocationCoordinate2D(center); + + if (duration) + { + CAMediaTimingFunction *function = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; + animationOptions.easing.emplace(MLNUnitBezierForMediaTimingFunction(function)); + } + } + + self.mbglMap.easeTo(cameraOptions, animationOptions); } } @@ -6460,7 +6476,7 @@ static void *windowScreenContext = &windowScreenContext; if (headingDirection >= 0 && self.userTrackingMode == MLNUserTrackingModeFollowWithHeading && self.userTrackingState != MLNUserTrackingStateBegan) { - [self _setDirection:headingDirection animated:YES]; + [self _setDirection:headingDirection center:self.userLocation.coordinate animated:YES]; [self updateUserLocationAnnotationView]; } });