diff options
Diffstat (limited to 'platform/macos/src/MGLMapView.mm')
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 0a1ec5516a..ad3d1eee51 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -1010,13 +1010,26 @@ public: } - (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate animated:(BOOL)animated { + [self setCenterCoordinate:centerCoordinate animated:animated completionHandler:nil]; +} + +- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion { MGLLogDebug(@"Setting centerCoordinate: %@ animated: %@", MGLStringFromCLLocationCoordinate2D(centerCoordinate), MGLStringFromBOOL(animated)); + mbgl::AnimationOptions animationOptions = MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0); + animationOptions.transitionFinishFn = ^() { + [self didChangeValueForKey:@"centerCoordinate"]; + if (completion) { + dispatch_async(dispatch_get_main_queue(), ^{ + completion(); + }); + } + }; + [self willChangeValueForKey:@"centerCoordinate"]; _mbglMap->easeTo(mbgl::CameraOptions() .withCenter(MGLLatLngFromLocationCoordinate2D(centerCoordinate)) .withPadding(MGLEdgeInsetsFromNSEdgeInsets(self.contentInsets)), - MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0)); - [self didChangeValueForKey:@"centerCoordinate"]; + animationOptions); } - (void)offsetCenterCoordinateBy:(NSPoint)delta animated:(BOOL)animated { @@ -1296,6 +1309,10 @@ public: } - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated { + [self setVisibleCoordinateBounds:bounds edgePadding:insets animated:animated completionHandler:nil]; +} + +- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion { _mbglMap->cancelTransitions(); mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); @@ -1308,12 +1325,18 @@ public: MGLMapCamera *camera = [self cameraForCameraOptions:cameraOptions]; if ([self.camera isEqualToMapCamera:camera]) { + completion(); return; } [self willChangeValueForKey:@"visibleCoordinateBounds"]; animationOptions.transitionFinishFn = ^() { [self didChangeValueForKey:@"visibleCoordinateBounds"]; + if (completion) { + dispatch_async(dispatch_get_main_queue(), ^{ + completion(); + }); + } }; _mbglMap->easeTo(cameraOptions, animationOptions); } @@ -1413,8 +1436,14 @@ public: } - (void)setContentInsets:(NSEdgeInsets)contentInsets animated:(BOOL)animated { - + [self setContentInsets:contentInsets animated:animated completionHandler:nil]; +} + +- (void)setContentInsets:(NSEdgeInsets)contentInsets animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion { if (NSEdgeInsetsEqual(contentInsets, self.contentInsets)) { + if (completion) { + completion(); + } return; } MGLLogDebug(@"Setting contentInset: %@ animated:", MGLStringFromNSEdgeInsets(contentInsets), MGLStringFromBOOL(animated)); @@ -1423,7 +1452,7 @@ public: // content insets. CLLocationCoordinate2D oldCenter = self.centerCoordinate; _contentInsets = contentInsets; - [self setCenterCoordinate:oldCenter animated:animated]; + [self setCenterCoordinate:oldCenter animated:animated completionHandler:completion]; } #pragma mark Mouse events and gestures @@ -2465,25 +2494,31 @@ public: } - (void)showAnnotations:(NSArray<id <MGLAnnotation>> *)annotations edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated { - if ( ! annotations || ! annotations.count) return; + [self showAnnotations:annotations edgePadding:insets animated:animated completionHandler:nil]; +} + +- (void)showAnnotations:(NSArray<id <MGLAnnotation>> *)annotations edgePadding:(NSEdgeInsets)insets animated:(BOOL)animated completionHandler:(nullable void (^)(void))completion { + if (!annotations.count) { + if (completion) { + completion(); + } + return; + } mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty(); - for (id <MGLAnnotation> annotation in annotations) - { - if ([annotation conformsToProtocol:@protocol(MGLOverlay)]) - { + for (id <MGLAnnotation> annotation in annotations) { + if ([annotation conformsToProtocol:@protocol(MGLOverlay)]) { bounds.extend(MGLLatLngBoundsFromCoordinateBounds(((id <MGLOverlay>)annotation).overlayBounds)); - } - else - { + } else { bounds.extend(MGLLatLngFromLocationCoordinate2D(annotation.coordinate)); } } [self setVisibleCoordinateBounds:MGLCoordinateBoundsFromLatLngBounds(bounds) edgePadding:insets - animated:animated]; + animated:animated + completionHandler:completion]; } /// Returns a popover detailing the annotation. |