diff options
author | Jason Wray <jason@mapbox.com> | 2017-08-29 17:42:38 -0400 |
---|---|---|
committer | Jason Wray <jason@mapbox.com> | 2017-09-07 19:23:29 -0400 |
commit | 218c720e9e8882e3d9070ce72ca3b4173c7835c8 (patch) | |
tree | 1af367075135c975eda786a627cc1dabb392a2d4 | |
parent | 99616e662704f3c778d002fc711ec1288fd6d142 (diff) | |
download | qtlocation-mapboxgl-218c720e9e8882e3d9070ce72ca3b4173c7835c8.tar.gz |
[ios] Add setShowsUserHeadingIndicator and validateUserHeadingUpdating
-rw-r--r-- | platform/ios/app/MBXViewController.m | 1 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.h | 17 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 47 |
3 files changed, 52 insertions, 13 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 40e5889526..6d9eafc042 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -160,6 +160,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { self.debugLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsDebugLoggingEnabled"]; self.mapView.scaleBar.hidden = NO; + self.mapView.showsUserHeadingIndicator = YES; self.hudLabel.hidden = YES; self.hudLabel.titleLabel.font = [UIFont monospacedDigitSystemFontOfSize:10 weight:UIFontWeightRegular]; diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index b475a21d2b..16a76ebcfe 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -358,6 +358,23 @@ MGL_EXPORT IB_DESIGNABLE - (void)setUserLocationVerticalAlignment:(MGLAnnotationVerticalAlignment)alignment animated:(BOOL)animated; /** + A Boolean value indicating whether the user location annotation may display a + permanent heading indicator. + + Setting this property to `YES` causes the default user location annotation to + always show an arrow-shaped heading indicator, if heading is available. This + property does not rotate the map; for that, see + `MGLUserTrackingModeFollowWithHeading`. + + This property has no effect when `userTrackingMode` is + `MGLUserTrackingModeFollowWithHeading` or + `MGLUserTrackingModeFollowWithCourse`. + + The default value of this property is `NO`. + */ +@property (nonatomic, assign) BOOL showsUserHeadingIndicator; + +/** Whether the map view should display a heading calibration alert when necessary. The default value is `YES`. */ 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]; |