Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

MGLUserTrackingModeFollowWithCourse #2068

Merged
merged 2 commits into from
Aug 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 3 additions & 1 deletion include/mbgl/ios/MGLTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 21 additions & 11 deletions ios/app/MBXViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,22 @@ - (void)cycleStyles

- (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:
nextMode = MGLUserTrackingModeFollowWithCourse;
break;
case MGLUserTrackingModeFollowWithCourse:
nextMode = MGLUserTrackingModeNone;
break;
}
self.mapView.userTrackingMode = nextMode;
}

#pragma mark - Destruction
Expand Down Expand Up @@ -402,6 +406,7 @@ - (UIColor *)mapView:(__unused MGLMapView *)mapView fillColorForPolygonAnnotatio
- (void)mapView:(__unused MGLMapView *)mapView didChangeUserTrackingMode:(MGLUserTrackingMode)mode animated:(__unused BOOL)animated
{
UIImage *newButtonImage;
NSString *newButtonTitle;

switch (mode) {
case MGLUserTrackingModeNone:
Expand All @@ -415,8 +420,13 @@ - (void)mapView:(__unused MGLMapView *)mapView didChangeUserTrackingMode:(MGLUse
case MGLUserTrackingModeFollowWithHeading:
newButtonImage = [UIImage imageNamed:@"TrackingHeadingMask.png"];
break;
case MGLUserTrackingModeFollowWithCourse:
newButtonImage = nil;
newButtonTitle = @"Course";
break;
}

self.navigationItem.rightBarButtonItem.title = newButtonTitle;
[UIView animateWithDuration:0.25 animations:^{
self.navigationItem.rightBarButtonItem.image = newButtonImage;
}];
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/settings_nsuserdefaults.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

unsigned uncheckedTrackingMode = [settings[@"trackingMode"] unsignedIntValue];
if (uncheckedTrackingMode > MGLUserTrackingModeNone &&
uncheckedTrackingMode <= MGLUserTrackingModeFollowWithHeading)
uncheckedTrackingMode <= MGLUserTrackingModeFollowWithCourse)
{
userTrackingMode = (MGLUserTrackingMode)uncheckedTrackingMode;
}
Expand Down
21 changes: 16 additions & 5 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,11 @@ - (void)handleCompassTapGesture:(__unused id)sender
{
[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
Expand Down Expand Up @@ -2278,7 +2282,8 @@ - (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated
{
if (mode == _userTrackingMode) return;

if (mode == MGLUserTrackingModeFollowWithHeading && ! CLLocationCoordinate2DIsValid(self.userLocation.coordinate))
if ((mode == MGLUserTrackingModeFollowWithHeading || mode == MGLUserTrackingModeFollowWithCourse) &&
! CLLocationCoordinate2DIsValid(self.userLocation.coordinate))
{
mode = MGLUserTrackingModeNone;
}
Expand All @@ -2288,7 +2293,6 @@ - (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated
switch (_userTrackingMode)
{
case MGLUserTrackingModeNone:
default:
{
[self.locationManager stopUpdatingHeading];

Expand All @@ -2311,6 +2315,7 @@ - (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated
break;
}
case MGLUserTrackingModeFollowWithHeading:
case MGLUserTrackingModeFollowWithCourse:
{
self.showsUserLocation = YES;

Expand Down Expand Up @@ -2404,6 +2409,12 @@ - (void)locationManager:(__unused CLLocationManager *)manager didUpdateToLocatio
}
}

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;

Expand Down Expand Up @@ -2432,9 +2443,9 @@ - (void)locationManager:(__unused CLLocationManager *)manager didUpdateHeading:(
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));
}
Expand Down
3 changes: 2 additions & 1 deletion platform/ios/MGLUserLocationAnnotationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ - (void)setupLayers
//
if (_headingIndicatorLayer)
{
_headingIndicatorLayer.hidden = (_mapView.userTrackingMode == MGLUserTrackingModeFollowWithHeading) ? NO : YES;
_headingIndicatorLayer.hidden = !(_mapView.userTrackingMode == MGLUserTrackingModeFollowWithHeading ||
_mapView.userTrackingMode == MGLUserTrackingModeFollowWithCourse);

if (_oldHeadingAccuracy != self.annotation.heading.headingAccuracy)
{
Expand Down