diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-01-24 11:38:10 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-01-26 17:17:25 -0800 |
commit | 87f0174967f6616229f6e7e3398f08ed283d8615 (patch) | |
tree | bf5b614a658e994c2dc0c22e95cf8e088e181ae0 | |
parent | 9dcaab193359f3de1a9d9750363cc547a2e69093 (diff) | |
download | qtlocation-mapboxgl-87f0174967f6616229f6e7e3398f08ed283d8615.tar.gz |
[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.
-rw-r--r-- | include/mbgl/ios/MGLMapView.h | 22 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 25 |
2 files changed, 43 insertions, 4 deletions
diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index 2d28fd3a14..c0f4cd1365 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,10 +248,25 @@ 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 3fa5ba78b0..0e9b1ccf4a 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) { @@ -3068,10 +3082,15 @@ 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]; } } |