[ios] Various user tracking mode fixes

Setting the user tracking mode without animation now works. Previously, it kept the user dot from ever updating.

Just as a zoom gesture no longer kicks the user out of user tracking mode, programmatically zooming shouldn’t either.

Setting a camera with an invalid center coordinate no longer attempts to change the center coordinate but still changes any other valid properties.

Made animation to new user dot vertical alignment optional.
This commit is contained in:
Minh Nguyễn
2016-01-24 11:38:10 -08:00
committed by Minh Nguyễn
parent 9dcaab1933
commit 87f0174967
2 changed files with 43 additions and 4 deletions

View File

@@ -224,7 +224,12 @@ IB_DESIGNABLE
@property (nonatomic, readonly, nullable) MGLUserLocation *userLocation;
/**
The mode used to track the user location.
The mode used to track the user location. The default value is
`MGLUserTrackingModeNone`.
Changing the value of this property updates the map view with an animated
transition. If you don’t want to animate the change, use the
`-setUserTrackingMode:animated:` method instead.
*/
@property (nonatomic, assign) MGLUserTrackingMode userTrackingMode;
@@ -243,9 +248,24 @@ IB_DESIGNABLE
/**
The vertical alignment of the user location annotation within the receiver. The
default value is `MGLAnnotationVerticalAlignmentCenter`.
Changing the value of this property updates the map view with an animated
transition. If you don’t want to animate the change, use the
`-setUserLocationVerticalAlignment:animated:` method instead.
*/
@property (nonatomic, assign) MGLAnnotationVerticalAlignment userLocationVerticalAlignment;
/**
Sets the vertical alignment of the user location annotation within the
receiver, with an optional transition.
@param alignment The vertical alignment of the user location annotation.
@param animated If `YES`, the user location annotation animates to its new
position within the map view. If `NO`, the user location annotation
instantaneously moves to its new position.
*/
- (void)setUserLocationVerticalAlignment:(MGLAnnotationVerticalAlignment)alignment animated:(BOOL)animated;
/**
Whether the map view should display a heading calibration alert when necessary.
The default value is `YES`.

View File

@@ -1756,7 +1756,14 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (void)setZoomLevel:(double)zoomLevel animated:(BOOL)animated
{
[self setCenterCoordinate:self.centerCoordinate zoomLevel:zoomLevel animated:animated];
if (zoomLevel == self.zoomLevel) return;
_mbglMap->cancelTransitions();
CGFloat duration = animated ? MGLAnimationDuration : 0;
_mbglMap->setZoom(zoomLevel,
MGLEdgeInsetsFromNSEdgeInsets(self.contentInset),
MGLDurationInSeconds(duration));
}
- (MGLCoordinateBounds)visibleCoordinateBounds
@@ -2021,7 +2028,10 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
- (mbgl::CameraOptions)cameraOptionsObjectForAnimatingToCamera:(MGLMapCamera *)camera
{
mbgl::CameraOptions options;
options.center = MGLLatLngFromLocationCoordinate2D(camera.centerCoordinate);
if (CLLocationCoordinate2DIsValid(camera.centerCoordinate))
{
options.center = MGLLatLngFromLocationCoordinate2D(camera.centerCoordinate);
}
options.padding = MGLEdgeInsetsFromNSEdgeInsets(self.contentInset);
options.zoom = MGLZoomLevelForAltitude(camera.altitude, camera.pitch,
camera.centerCoordinate.latitude,
@@ -3010,6 +3020,10 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
self.userTrackingState = MGLUserTrackingStatePossible;
}
if ( ! animated)
{
self.userTrackingState = MGLUserTrackingStateChanged;
}
switch (_userTrackingMode)
{
@@ -3067,11 +3081,16 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
}
- (void)setUserLocationVerticalAlignment:(MGLAnnotationVerticalAlignment)alignment
{
[self setUserLocationVerticalAlignment:alignment animated:YES];
}
- (void)setUserLocationVerticalAlignment:(MGLAnnotationVerticalAlignment)alignment animated:(BOOL)animated
{
_userLocationVerticalAlignment = alignment;
if (self.userTrackingMode != MGLUserTrackingModeNone)
{
[self locationManager:self.locationManager didUpdateLocations:@[self.userLocation.location] animated:YES];
[self locationManager:self.locationManager didUpdateLocations:@[self.userLocation.location] animated:animated];
}
}