[ios] Add setShowsUserHeadingIndicator and validateUserHeadingUpdating

This commit is contained in:
Jason Wray
2017-08-29 17:42:38 -04:00
parent 99616e6627
commit 218c720e9e
3 changed files with 52 additions and 13 deletions

View File

@@ -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];

View File

@@ -357,6 +357,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`.

View File

@@ -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];