summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-08-13 10:00:05 -0700
committerMinh Nguyễn <mxn@1ec5.org>2015-08-14 10:09:43 -0700
commitdfeb479011bbbd99de37863f5bea5fc1a8b0e02c (patch)
tree844105e4548c5dee74c8938b0802f8ee117d3679
parent2f316878448d0056b5c4ced6ce0819349eaf466e (diff)
downloadqtlocation-mapboxgl-dfeb479011bbbd99de37863f5bea5fc1a8b0e02c.tar.gz
MGLUserTrackingModeFollowWithCourse
Added course-tracking. However, rotation has to happen atomically without animation until #1834 is fixed. Fixes #1605.
-rw-r--r--include/mbgl/ios/MGLMapView.h2
-rw-r--r--include/mbgl/ios/MGLTypes.h4
-rw-r--r--ios/app/MBXViewController.mm25
-rw-r--r--platform/darwin/settings_nsuserdefaults.mm2
-rw-r--r--platform/ios/MGLMapView.mm21
-rw-r--r--platform/ios/MGLUserLocationAnnotationView.m3
6 files changed, 37 insertions, 20 deletions
diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h
index 913d497631..2b9a3d2913 100644
--- a/include/mbgl/ios/MGLMapView.h
+++ b/include/mbgl/ios/MGLMapView.h
@@ -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.
*
diff --git a/include/mbgl/ios/MGLTypes.h b/include/mbgl/ios/MGLTypes.h
index 75a0d4619f..f36fc3f44e 100644
--- a/include/mbgl/ios/MGLTypes.h
+++ b/include/mbgl/ios/MGLTypes.h
@@ -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
diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm
index e11f7eea5c..037a6a02ca 100644
--- a/ios/app/MBXViewController.mm
+++ b/ios/app/MBXViewController.mm
@@ -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;
}
diff --git a/platform/darwin/settings_nsuserdefaults.mm b/platform/darwin/settings_nsuserdefaults.mm
index 168cba172d..f6f9bbeedb 100644
--- a/platform/darwin/settings_nsuserdefaults.mm
+++ b/platform/darwin/settings_nsuserdefaults.mm
@@ -30,7 +30,7 @@ void Settings_NSUserDefaults::load()
unsigned uncheckedTrackingMode = [settings[@"trackingMode"] unsignedIntValue];
if (uncheckedTrackingMode > MGLUserTrackingModeNone &&
- uncheckedTrackingMode <= MGLUserTrackingModeFollowWithHeading)
+ uncheckedTrackingMode <= MGLUserTrackingModeFollowWithCourse)
{
userTrackingMode = (MGLUserTrackingMode)uncheckedTrackingMode;
}
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index edb3d74a3f..db18ea0128 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -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));
}
diff --git a/platform/ios/MGLUserLocationAnnotationView.m b/platform/ios/MGLUserLocationAnnotationView.m
index 536326d1f6..7733674e63 100644
--- a/platform/ios/MGLUserLocationAnnotationView.m
+++ b/platform/ios/MGLUserLocationAnnotationView.m
@@ -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)
{