diff options
Diffstat (limited to 'platform/ios/src/MGLMapView.mm')
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 176 |
1 files changed, 111 insertions, 65 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 9693e3cff9..45eb345149 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1021,22 +1021,30 @@ public: - (void)setContentInset:(UIEdgeInsets)contentInset animated:(BOOL)animated { + [self setContentInset:contentInset animated:animated completionHandler:nil]; +} + +- (void)setContentInset:(UIEdgeInsets)contentInset animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion +{ MGLLogDebug(@"Setting contentInset: %@ animated:", NSStringFromUIEdgeInsets(contentInset), MGLStringFromBOOL(animated)); if (UIEdgeInsetsEqualToEdgeInsets(contentInset, self.contentInset)) { + if (completion) { + completion(); + } return; } if (self.userTrackingMode == MGLUserTrackingModeNone) { // Don’t call -setCenterCoordinate:, which resets the user tracking mode. - [self _setCenterCoordinate:self.centerCoordinate edgePadding:contentInset zoomLevel:self.zoomLevel direction:self.direction duration:animated ? MGLAnimationDuration : 0 animationTimingFunction:nil completionHandler:nil]; + [self _setCenterCoordinate:self.centerCoordinate edgePadding:contentInset zoomLevel:self.zoomLevel direction:self.direction duration:animated ? MGLAnimationDuration : 0 animationTimingFunction:nil completionHandler:completion]; _contentInset = contentInset; } else { _contentInset = contentInset; - [self didUpdateLocationWithUserTrackingAnimated:animated]; + [self didUpdateLocationWithUserTrackingAnimated:animated completionHandler:completion]; } // Compass, logo and attribution button constraints needs to be updated.z @@ -1873,7 +1881,7 @@ public: { CGPoint calloutPoint = [singleTap locationInView:self]; CGRect positionRect = [self positioningRectForAnnotation:annotation defaultCalloutPoint:calloutPoint]; - [self selectAnnotation:annotation moveIntoView:YES animateSelection:YES calloutPositioningRect:positionRect]; + [self selectAnnotation:annotation moveIntoView:YES animateSelection:YES calloutPositioningRect:positionRect completionHandler:nil]; } else if (self.selectedAnnotation) { @@ -3331,28 +3339,14 @@ public: - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated { - MGLLogDebug(@"Setting visibleCoordinateBounds: %@ edgePadding: %@ animated: %@", - MGLStringFromCoordinateBounds(bounds), - NSStringFromUIEdgeInsets(insets), - MGLStringFromBOOL(animated)); - CLLocationCoordinate2D coordinates[] = { - {bounds.ne.latitude, bounds.sw.longitude}, - bounds.sw, - {bounds.sw.latitude, bounds.ne.longitude}, - bounds.ne, - }; - [self setVisibleCoordinates:coordinates - count:sizeof(coordinates) / sizeof(coordinates[0]) - edgePadding:insets - animated:animated]; + [self setVisibleCoordinateBounds:bounds edgePadding:insets animated:animated completionHandler:nil]; } -- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction animated:(BOOL)animated +- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion { - MGLLogDebug(@"Setting visibleCoordinateBounds: %@ edgePadding: %@ direction: %f animated: %@", + MGLLogDebug(@"Setting visibleCoordinateBounds: %@ edgePadding: %@ animated: %@", MGLStringFromCoordinateBounds(bounds), NSStringFromUIEdgeInsets(insets), - direction, MGLStringFromBOOL(animated)); CLLocationCoordinate2D coordinates[] = { {bounds.ne.latitude, bounds.sw.longitude}, @@ -3363,8 +3357,10 @@ public: [self setVisibleCoordinates:coordinates count:sizeof(coordinates) / sizeof(coordinates[0]) edgePadding:insets - direction:direction - animated:animated]; + direction:self.direction + duration:animated ? MGLAnimationDuration : 0 + animationTimingFunction:nil + completionHandler:completion]; } - (void)setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated @@ -3373,17 +3369,7 @@ public: count, NSStringFromUIEdgeInsets(insets), MGLStringFromBOOL(animated)); - [self setVisibleCoordinates:coordinates count:count edgePadding:insets direction:self.direction animated:animated]; -} - -- (void)setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction animated:(BOOL)animated -{ - MGLLogDebug(@"Setting: %lu coordinates edgePadding: %@ direction: %f animated: %@", - count, - NSStringFromUIEdgeInsets(insets), - direction, - MGLStringFromBOOL(animated)); - [self setVisibleCoordinates:coordinates count:count edgePadding:insets direction:direction duration:animated ? MGLAnimationDuration : 0 animationTimingFunction:nil]; + [self setVisibleCoordinates:coordinates count:count edgePadding:insets direction:self.direction duration:animated ? MGLAnimationDuration : 0 animationTimingFunction:nil]; } - (void)setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function { @@ -4699,17 +4685,22 @@ public: - (void)selectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animated { - [self selectAnnotation:annotation moveIntoView:animated animateSelection:animated]; + [self selectAnnotation:annotation animated:animated completionHandler:nil]; } -- (void)selectAnnotation:(id <MGLAnnotation>)annotation moveIntoView:(BOOL)moveIntoView animateSelection:(BOOL)animateSelection +- (void)selectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion +{ + [self selectAnnotation:annotation moveIntoView:animated animateSelection:animated completionHandler:completion]; +} + +- (void)selectAnnotation:(id <MGLAnnotation>)annotation moveIntoView:(BOOL)moveIntoView animateSelection:(BOOL)animateSelection completionHandler:(nullable void (^)(void))completion { MGLLogDebug(@"Selecting annotation: %@ moveIntoView: %@ animateSelection: %@", annotation, MGLStringFromBOOL(moveIntoView), MGLStringFromBOOL(animateSelection)); CGRect positioningRect = [self positioningRectForAnnotation:annotation defaultCalloutPoint:CGPointZero]; - [self selectAnnotation:annotation moveIntoView:moveIntoView animateSelection:animateSelection calloutPositioningRect:positioningRect]; + [self selectAnnotation:annotation moveIntoView:moveIntoView animateSelection:animateSelection calloutPositioningRect:positioningRect completionHandler:completion]; } -- (void)selectAnnotation:(id <MGLAnnotation>)annotation moveIntoView:(BOOL)moveIntoView animateSelection:(BOOL)animateSelection calloutPositioningRect:(CGRect)calloutPositioningRect +- (void)selectAnnotation:(id <MGLAnnotation>)annotation moveIntoView:(BOOL)moveIntoView animateSelection:(BOOL)animateSelection calloutPositioningRect:(CGRect)calloutPositioningRect completionHandler:(nullable void (^)(void))completion { if ( ! annotation) return; @@ -4919,7 +4910,11 @@ public: { CGPoint center = CGPointMake(CGRectGetMidX(constrainedRect), CGRectGetMidY(constrainedRect)); CLLocationCoordinate2D centerCoord = [self convertPoint:center toCoordinateFromView:self]; - [self setCenterCoordinate:centerCoord animated:animateSelection]; + [self setCenterCoordinate:centerCoord zoomLevel:self.zoomLevel direction:self.direction animated:animateSelection completionHandler:completion]; + } + else if (completion) + { + completion(); } } @@ -5117,8 +5112,19 @@ public: - (void)showAnnotations:(NSArray<id <MGLAnnotation>> *)annotations edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated { + [self showAnnotations:annotations edgePadding:insets animated:animated completionHandler:nil]; +} + +- (void)showAnnotations:(NSArray<id <MGLAnnotation>> *)annotations edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion +{ MGLLogDebug(@"Showing: %lu annotations edgePadding: %@ animated: %@", annotations.count, NSStringFromUIEdgeInsets(insets), MGLStringFromBOOL(animated)); - if ( ! annotations || ! annotations.count) return; + if ( ! annotations.count) + { + if (completion) { + completion(); + } + return; + } mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty(); @@ -5136,7 +5142,8 @@ public: [self setVisibleCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(bounds) edgePadding:insets - animated:animated]; + animated:animated + completionHandler:completion]; } @@ -5345,8 +5352,20 @@ public: - (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated { + [self setUserTrackingMode:mode animated:animated completionHandler:nil]; +} + +- (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion +{ MGLLogDebug(@"Setting userTrackingMode: %lu animated: %@", mode, MGLStringFromBOOL(animated)); - if (mode == _userTrackingMode) return; + if (mode == _userTrackingMode) + { + if (completion) + { + completion(); + } + return; + } MGLUserTrackingMode oldMode = _userTrackingMode; [self willChangeValueForKey:@"userTrackingMode"]; @@ -5391,13 +5410,14 @@ public: } } - if (_userTrackingMode != MGLUserTrackingModeNone) + CLLocation *location; + if (_userTrackingMode != MGLUserTrackingModeNone && (location = self.userLocation.location) && self.userLocationAnnotationView) { - CLLocation *location = self.userLocation.location; - if (location && self.userLocationAnnotationView) - { - [self locationManager:self.locationManager didUpdateLocations:@[location] animated:animated]; - } + [self locationManager:self.locationManager didUpdateLocations:@[location] animated:animated completionHandler:completion]; + } + else if (completion) + { + completion(); } [self validateUserHeadingUpdating]; @@ -5421,7 +5441,7 @@ public: CLLocation *location = self.userLocation.location; if (location) { - [self locationManager:self.locationManager didUpdateLocations:@[location] animated:animated]; + [self locationManager:self.locationManager didUpdateLocations:@[location] animated:animated completionHandler:nil]; } } } @@ -5434,7 +5454,13 @@ public: - (void)setTargetCoordinate:(CLLocationCoordinate2D)targetCoordinate animated:(BOOL)animated { + [self setTargetCoordinate:targetCoordinate animated:animated completionHandler:nil]; +} + +- (void)setTargetCoordinate:(CLLocationCoordinate2D)targetCoordinate animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion +{ MGLLogDebug(@"Setting targetCoordinate: %@ animated: %@", MGLStringFromCLLocationCoordinate2D(targetCoordinate), MGLStringFromBOOL(animated)); + BOOL isSynchronous = YES; if (targetCoordinate.latitude != self.targetCoordinate.latitude || targetCoordinate.longitude != self.targetCoordinate.longitude) { @@ -5443,13 +5469,17 @@ public: { self.userTrackingState = MGLUserTrackingStatePossible; - CLLocation *location = self.userLocation.location; - if (location) + if (CLLocation *location = self.userLocation.location) { - [self locationManager:self.locationManager didUpdateLocations:@[location] animated:animated]; + isSynchronous = NO; + [self locationManager:self.locationManager didUpdateLocations:@[location] animated:animated completionHandler:completion]; } } } + if (isSynchronous && completion) + { + completion(); + } } - (void)setShowsUserHeadingIndicator:(BOOL)showsUserHeadingIndicator @@ -5481,10 +5511,10 @@ public: - (void)locationManager:(id<MGLLocationManager>)manager didUpdateLocations:(NSArray *)locations { - [self locationManager:manager didUpdateLocations:locations animated:YES]; + [self locationManager:manager didUpdateLocations:locations animated:YES completionHandler:nil]; } -- (void)locationManager:(__unused id<MGLLocationManager>)manager didUpdateLocations:(NSArray *)locations animated:(BOOL)animated +- (void)locationManager:(__unused id<MGLLocationManager>)manager didUpdateLocations:(NSArray *)locations animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion { CLLocation *oldLocation = self.userLocation.location; CLLocation *newLocation = locations.lastObject; @@ -5506,7 +5536,7 @@ public: } } - [self didUpdateLocationWithUserTrackingAnimated:animated]; + [self didUpdateLocationWithUserTrackingAnimated:animated completionHandler:completion]; NSTimeInterval duration = MGLAnimationDuration; if (oldLocation && ! CGPointEqualToPoint(self.userLocationAnnotationView.center, CGPointZero)) @@ -5523,13 +5553,17 @@ public: } } -- (void)didUpdateLocationWithUserTrackingAnimated:(BOOL)animated +- (void)didUpdateLocationWithUserTrackingAnimated:(BOOL)animated completionHandler:(nullable void (^)(void))completion { CLLocation *location = self.userLocation.location; if ( ! _showsUserLocation || ! location || ! CLLocationCoordinate2DIsValid(location.coordinate) || self.userTrackingMode == MGLUserTrackingModeNone) { + if (completion) + { + completion(); + } return; } @@ -5540,6 +5574,10 @@ public: if (std::abs(currentPoint.x - correctPoint.x) <= 1.0 && std::abs(currentPoint.y - correctPoint.y) <= 1.0 && self.userTrackingMode != MGLUserTrackingModeFollowWithCourse) { + if (completion) + { + completion(); + } return; } @@ -5549,25 +5587,25 @@ public: if (self.userTrackingState != MGLUserTrackingStateBegan) { // Keep both the user and the destination in view. - [self didUpdateLocationWithTargetAnimated:animated]; + [self didUpdateLocationWithTargetAnimated:animated completionHandler:completion]; } } else if (self.userTrackingState == MGLUserTrackingStatePossible) { // The first location update is often a great distance away from the // current viewport, so fly there to provide additional context. - [self didUpdateLocationSignificantlyAnimated:animated]; + [self didUpdateLocationSignificantlyAnimated:animated completionHandler:completion]; } else if (self.userTrackingState == MGLUserTrackingStateChanged) { // Subsequent updates get a more subtle animation. - [self didUpdateLocationIncrementallyAnimated:animated]; + [self didUpdateLocationIncrementallyAnimated:animated completionHandler:completion]; } [self unrotateIfNeededAnimated:YES]; } /// Changes the viewport based on an incremental location update. -- (void)didUpdateLocationIncrementallyAnimated:(BOOL)animated +- (void)didUpdateLocationIncrementallyAnimated:(BOOL)animated completionHandler:(nullable void (^)(void))completion { [self _setCenterCoordinate:self.userLocation.location.coordinate edgePadding:self.edgePaddingForFollowing @@ -5575,12 +5613,12 @@ public: direction:self.directionByFollowingWithCourse duration:animated ? MGLUserLocationAnimationDuration : 0 animationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear] - completionHandler:nil]; + completionHandler:completion]; } /// Changes the viewport based on a significant location update, such as the /// first location update. -- (void)didUpdateLocationSignificantlyAnimated:(BOOL)animated +- (void)didUpdateLocationSignificantlyAnimated:(BOOL)animated completionHandler:(nullable void (^)(void))completion { if (_distanceFromOldUserLocation >= MGLDistanceThresholdForCameraPause) { @@ -5612,25 +5650,33 @@ public: { strongSelf.userTrackingState = MGLUserTrackingStateChanged; } + if (completion) + { + completion(); + } }]; } /// Changes the viewport based on a location update in the presence of a target /// coordinate that must also be displayed on the map concurrently. -- (void)didUpdateLocationWithTargetAnimated:(BOOL)animated +- (void)didUpdateLocationWithTargetAnimated:(BOOL)animated completionHandler:(nullable void (^)(void))completion { BOOL firstUpdate = self.userTrackingState == MGLUserTrackingStatePossible; - void (^completion)(void); + void (^animationCompletion)(void); if (animated && firstUpdate) { self.userTrackingState = MGLUserTrackingStateBegan; __weak MGLMapView *weakSelf = self; - completion = ^{ + animationCompletion = ^{ MGLMapView *strongSelf = weakSelf; if (strongSelf.userTrackingState == MGLUserTrackingStateBegan) { strongSelf.userTrackingState = MGLUserTrackingStateChanged; } + if (completion) + { + completion(); + } }; } @@ -5654,7 +5700,7 @@ public: direction:self.directionByFollowingWithCourse duration:animated ? MGLUserLocationAnimationDuration : 0 animationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear] - completionHandler:completion]; + completionHandler:animationCompletion]; } /// Returns the edge padding to apply when moving the map to a tracked location. |