From 218c720e9e8882e3d9070ce72ca3b4173c7835c8 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Tue, 29 Aug 2017 17:42:38 -0400 Subject: [ios] Add setShowsUserHeadingIndicator and validateUserHeadingUpdating --- platform/ios/src/MGLMapView.mm | 47 ++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'platform/ios/src/MGLMapView.mm') diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 320c4bcda8..9f5ccaaa77 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -872,10 +872,14 @@ public: if (self.compassView.alpha) { - [self updateHeadingForDeviceOrientation]; [self updateCompass]; } + if (self.compassView.alpha || self.showsUserHeadingIndicator) + { + [self updateHeadingForDeviceOrientation]; + } + [self updateUserLocationAnnotationView]; } @@ -4195,10 +4199,7 @@ public: self.locationManager.delegate = self; [self.locationManager startUpdatingLocation]; - if (self.userTrackingMode == MGLUserTrackingModeFollowWithHeading) - { - [self.locationManager startUpdatingHeading]; - } + [self validateUserHeadingUpdating]; } else if ( ! shouldEnableLocationServices && self.locationManager) { @@ -4322,8 +4323,6 @@ public: { self.userTrackingState = MGLUserTrackingStatePossible; - [self.locationManager stopUpdatingHeading]; - // Immediately update the annotation view; other cases update inside // the locationManager:didUpdateLocations: method. [self updateUserLocationAnnotationView]; @@ -4336,8 +4335,6 @@ public: self.userTrackingState = animated ? MGLUserTrackingStatePossible : MGLUserTrackingStateChanged; self.showsUserLocation = YES; - [self.locationManager stopUpdatingHeading]; - break; } case MGLUserTrackingModeFollowWithHeading: @@ -4354,10 +4351,6 @@ public: [self setZoomLevel:self.currentMinimumZoom animated:YES]; } - [self updateHeadingForDeviceOrientation]; - - [self.locationManager startUpdatingHeading]; - break; } } @@ -4371,6 +4364,8 @@ public: } } + [self validateUserHeadingUpdating]; + if ([self.delegate respondsToSelector:@selector(mapView:didChangeUserTrackingMode:animated:)]) { [self.delegate mapView:self didChangeUserTrackingMode:_userTrackingMode animated:animated]; @@ -4419,6 +4414,27 @@ public: } } +- (void)setShowsUserHeadingIndicator:(BOOL)showsUserHeadingIndicator +{ + _showsUserHeadingIndicator = showsUserHeadingIndicator; + [self validateUserHeadingUpdating]; +} + +- (void)validateUserHeadingUpdating +{ + BOOL canShowPermanentHeadingIndicator = self.showsUserHeadingIndicator && self.userTrackingMode != MGLUserTrackingModeFollowWithCourse; + + if (self.showsUserLocation && (canShowPermanentHeadingIndicator || self.userTrackingMode == MGLUserTrackingModeFollowWithHeading)) + { + [self updateHeadingForDeviceOrientation]; + [self.locationManager startUpdatingHeading]; + } + else + { + [self.locationManager stopUpdatingHeading]; + } +} + - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { [self locationManager:manager didUpdateLocations:locations animated:YES]; @@ -4666,6 +4682,11 @@ public: self.userLocation.heading = newHeading; + if (self.showsUserHeadingIndicator || self.userTrackingMode == MGLUserTrackingModeFollowWithHeading) + { + [self updateUserLocationAnnotationView]; + } + if ([self.delegate respondsToSelector:@selector(mapView:didUpdateUserLocation:)]) { [self.delegate mapView:self didUpdateUserLocation:self.userLocation]; -- cgit v1.2.1