diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index 2d28fd3a1..c0f4cd136 100644 --- a/include/mbgl/ios/MGLMapView.h +++ b/include/mbgl/ios/MGLMapView.h @@ -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`. diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 3fa5ba78b..0e9b1ccf4 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -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]; } }