MGLUserTrackingModeFollowWithCourse
Added course-tracking. However, rotation has to happen atomically without animation until #1834 is fixed. Fixes #1605.
This commit is contained in:
@@ -486,7 +486,7 @@ IB_DESIGNABLE
|
||||
|
||||
/** Tells the delegate that the location of the user was updated.
|
||||
*
|
||||
* While the showsUserLocation property is set to `YES`, this method is called whenever a new location update is received by the map view. This method is also called if the map view’s user tracking mode is set to MGLUserTrackingModeFollowWithHeading and the heading changes.
|
||||
* While the showsUserLocation property is set to `YES`, this method is called whenever a new location update is received by the map view. This method is also called if the map view’s user tracking mode is set to MGLUserTrackingModeFollowWithHeading and the heading changes, or if it is set to MGLUserTrackingModeFollowWithCourse and the course changes.
|
||||
*
|
||||
* This method is not called if the application is currently running in the background. If you want to receive location updates while running in the background, you must use the Core Location framework.
|
||||
*
|
||||
|
||||
@@ -21,7 +21,9 @@ typedef NS_ENUM(NSUInteger, MGLUserTrackingMode) {
|
||||
/** The map follows the user location. */
|
||||
MGLUserTrackingModeFollow,
|
||||
/** The map follows the user location and rotates when the heading changes. */
|
||||
MGLUserTrackingModeFollowWithHeading
|
||||
MGLUserTrackingModeFollowWithHeading,
|
||||
/** The map follows the user location and rotates when the course changes. */
|
||||
MGLUserTrackingModeFollowWithCourse,
|
||||
};
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -310,18 +310,20 @@ mbgl::Settings_NSUserDefaults *settings = nullptr;
|
||||
|
||||
- (void)locateUser
|
||||
{
|
||||
if (self.mapView.userTrackingMode == MGLUserTrackingModeNone)
|
||||
{
|
||||
self.mapView.userTrackingMode = MGLUserTrackingModeFollow;
|
||||
}
|
||||
else if (self.mapView.userTrackingMode == MGLUserTrackingModeFollow)
|
||||
{
|
||||
self.mapView.userTrackingMode = MGLUserTrackingModeFollowWithHeading;
|
||||
}
|
||||
else
|
||||
{
|
||||
self.mapView.userTrackingMode = MGLUserTrackingModeNone;
|
||||
MGLUserTrackingMode nextMode;
|
||||
switch (self.mapView.userTrackingMode) {
|
||||
case MGLUserTrackingModeNone:
|
||||
nextMode = MGLUserTrackingModeFollow;
|
||||
break;
|
||||
case MGLUserTrackingModeFollow:
|
||||
nextMode = MGLUserTrackingModeFollowWithHeading;
|
||||
break;
|
||||
case MGLUserTrackingModeFollowWithHeading:
|
||||
case MGLUserTrackingModeFollowWithCourse:
|
||||
nextMode = MGLUserTrackingModeNone;
|
||||
break;
|
||||
}
|
||||
self.mapView.userTrackingMode = nextMode;
|
||||
}
|
||||
|
||||
#pragma mark - Destruction
|
||||
@@ -413,6 +415,7 @@ mbgl::Settings_NSUserDefaults *settings = nullptr;
|
||||
break;
|
||||
|
||||
case MGLUserTrackingModeFollowWithHeading:
|
||||
case MGLUserTrackingModeFollowWithCourse:
|
||||
newButtonImage = [UIImage imageNamed:@"TrackingHeadingMask.png"];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ void Settings_NSUserDefaults::load()
|
||||
|
||||
unsigned uncheckedTrackingMode = [settings[@"trackingMode"] unsignedIntValue];
|
||||
if (uncheckedTrackingMode > MGLUserTrackingModeNone &&
|
||||
uncheckedTrackingMode <= MGLUserTrackingModeFollowWithHeading)
|
||||
uncheckedTrackingMode <= MGLUserTrackingModeFollowWithCourse)
|
||||
{
|
||||
userTrackingMode = (MGLUserTrackingMode)uncheckedTrackingMode;
|
||||
}
|
||||
|
||||
@@ -828,7 +828,11 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
|
||||
{
|
||||
[self resetNorthAnimated:YES];
|
||||
|
||||
if (self.userTrackingMode == MGLUserTrackingModeFollowWithHeading) self.userTrackingMode = MGLUserTrackingModeFollow;
|
||||
if (self.userTrackingMode == MGLUserTrackingModeFollowWithHeading ||
|
||||
self.userTrackingMode == MGLUserTrackingModeFollowWithCourse)
|
||||
{
|
||||
self.userTrackingMode = MGLUserTrackingModeFollow;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(__unused NS_SET_OF(UITouch *) *)touches withEvent:(__unused UIEvent *)event
|
||||
@@ -2278,7 +2282,8 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
|
||||
{
|
||||
if (mode == _userTrackingMode) return;
|
||||
|
||||
if (mode == MGLUserTrackingModeFollowWithHeading && ! CLLocationCoordinate2DIsValid(self.userLocation.coordinate))
|
||||
if ((mode == MGLUserTrackingModeFollowWithHeading || mode == MGLUserTrackingModeFollowWithCourse) &&
|
||||
! CLLocationCoordinate2DIsValid(self.userLocation.coordinate))
|
||||
{
|
||||
mode = MGLUserTrackingModeNone;
|
||||
}
|
||||
@@ -2288,7 +2293,6 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
|
||||
switch (_userTrackingMode)
|
||||
{
|
||||
case MGLUserTrackingModeNone:
|
||||
default:
|
||||
{
|
||||
[self.locationManager stopUpdatingHeading];
|
||||
|
||||
@@ -2311,6 +2315,7 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
|
||||
break;
|
||||
}
|
||||
case MGLUserTrackingModeFollowWithHeading:
|
||||
case MGLUserTrackingModeFollowWithCourse:
|
||||
{
|
||||
self.showsUserLocation = YES;
|
||||
|
||||
@@ -2404,6 +2409,12 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
|
||||
}
|
||||
}
|
||||
|
||||
CLLocationDirection course = self.userLocation.location.course;
|
||||
if (course >= 0 && self.userTrackingMode == MGLUserTrackingModeFollowWithCourse)
|
||||
{
|
||||
_mbglMap->setBearing(course);
|
||||
}
|
||||
|
||||
self.userLocationAnnotationView.haloLayer.hidden = ! CLLocationCoordinate2DIsValid(self.userLocation.coordinate) ||
|
||||
newLocation.horizontalAccuracy > 10;
|
||||
|
||||
@@ -2432,9 +2443,9 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
|
||||
if ( ! _showsUserLocation) return;
|
||||
}
|
||||
|
||||
CLLocationDirection headingDirection = (newHeading.trueHeading > 0 ? newHeading.trueHeading : newHeading.magneticHeading);
|
||||
CLLocationDirection headingDirection = (newHeading.trueHeading >= 0 ? newHeading.trueHeading : newHeading.magneticHeading);
|
||||
|
||||
if (headingDirection > 0 && self.userTrackingMode == MGLUserTrackingModeFollowWithHeading)
|
||||
if (headingDirection >= 0 && self.userTrackingMode == MGLUserTrackingModeFollowWithHeading)
|
||||
{
|
||||
_mbglMap->setBearing(headingDirection, secondsAsDuration(MGLAnimationDuration));
|
||||
}
|
||||
|
||||
@@ -74,7 +74,8 @@ const CGFloat MGLUserLocationAnnotationHaloSize = 115.0;
|
||||
//
|
||||
if (_headingIndicatorLayer)
|
||||
{
|
||||
_headingIndicatorLayer.hidden = (_mapView.userTrackingMode == MGLUserTrackingModeFollowWithHeading) ? NO : YES;
|
||||
_headingIndicatorLayer.hidden = !(_mapView.userTrackingMode == MGLUserTrackingModeFollowWithHeading ||
|
||||
_mapView.userTrackingMode == MGLUserTrackingModeFollowWithCourse);
|
||||
|
||||
if (_oldHeadingAccuracy != self.annotation.heading.headingAccuracy)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user