diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-11-20 01:28:01 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2017-02-18 14:14:09 -0800 |
commit | d790132eda070c652b1d3a6ac44dc5d7e66335f4 (patch) | |
tree | 9536dbea1399cc9bb0e0a1f22609f1da51896d61 /platform/ios/src | |
parent | 28ad35fc0461aa89b490e3b187fca5374f18596d (diff) | |
download | qtlocation-mapboxgl-d790132eda070c652b1d3a6ac44dc5d7e66335f4.tar.gz |
[ios, macos] Short-circuit redundant camera changes
Avoid canceling transitions (and triggering preexisting completion handlers) until we get a chance to ensure that a new transition really does have to begin. Consistently avoid mbgl transitions for redundant camera changes. Upon bailing, schedule the completion handler to run asynchronously on a delay equivalent to the requested animation duration.
Added a “functional” equality method to MGLMapCamera that avoids trivial differences.
Fixed invocations of XCTAssertEqualWithAccuracy() that incorrectly expressed the accuracy as a number of digits rather than a scalar tolerance.
Diffstat (limited to 'platform/ios/src')
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 74 |
1 files changed, 55 insertions, 19 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index fb056490ff..24d9fa0d8d 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2269,8 +2269,6 @@ public: - (void)_setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate edgePadding:(UIEdgeInsets)insets zoomLevel:(double)zoomLevel direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion { - _mbglMap->cancelTransitions(); - mbgl::CameraOptions cameraOptions; cameraOptions.center = MGLLatLngFromLocationCoordinate2D(centerCoordinate); cameraOptions.padding = MGLEdgeInsetsFromNSEdgeInsets(insets); @@ -2297,6 +2295,20 @@ public: }); }; } + + MGLMapCamera *camera = [self cameraForCameraOptions:cameraOptions]; + if ([self.camera isEqualToMapCamera:camera]) + { + if (completion) + { + [self animateWithDelay:duration animations:^{ + completion(); + }]; + } + return; + } + + _mbglMap->cancelTransitions(); _mbglMap->easeTo(cameraOptions, animationOptions); } @@ -2415,9 +2427,6 @@ public: - (void)_setVisibleCoordinates:(const CLLocationCoordinate2D *)coordinates count:(NSUInteger)count edgePadding:(UIEdgeInsets)insets direction:(CLLocationDirection)direction duration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion { - _mbglMap->cancelTransitions(); - - [self willChangeValueForKey:@"visibleCoordinateBounds"]; mbgl::EdgeInsets padding = MGLEdgeInsetsFromNSEdgeInsets(insets); padding += MGLEdgeInsetsFromNSEdgeInsets(self.contentInset); std::vector<mbgl::LatLng> latLngs; @@ -2447,6 +2456,21 @@ public: }); }; } + + MGLMapCamera *camera = [self cameraForCameraOptions:cameraOptions]; + if ([self.camera isEqualToMapCamera:camera]) + { + if (completion) + { + [self animateWithDelay:duration animations:^{ + completion(); + }]; + } + return; + } + + [self willChangeValueForKey:@"visibleCoordinateBounds"]; + _mbglMap->cancelTransitions(); _mbglMap->easeTo(cameraOptions, animationOptions); [self didChangeValueForKey:@"visibleCoordinateBounds"]; } @@ -2532,13 +2556,6 @@ public: - (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion { - _mbglMap->cancelTransitions(); - if ([self.camera isEqual:camera]) - { - return; - } - - mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera edgePadding:self.contentInset]; mbgl::AnimationOptions animationOptions; if (duration > 0) { @@ -2553,8 +2570,21 @@ public: }); }; } + + if ([self.camera isEqualToMapCamera:camera]) + { + if (completion) + { + [self animateWithDelay:duration animations:^{ + completion(); + }]; + } + return; + } [self willChangeValueForKey:@"camera"]; + _mbglMap->cancelTransitions(); + mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera edgePadding:self.contentInset]; _mbglMap->easeTo(cameraOptions, animationOptions); [self didChangeValueForKey:@"camera"]; } @@ -2576,13 +2606,6 @@ public: - (void)_flyToCamera:(MGLMapCamera *)camera edgePadding:(UIEdgeInsets)insets withDuration:(NSTimeInterval)duration peakAltitude:(CLLocationDistance)peakAltitude completionHandler:(nullable void (^)(void))completion { - _mbglMap->cancelTransitions(); - if ([self.camera isEqual:camera]) - { - return; - } - - mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera edgePadding:insets]; mbgl::AnimationOptions animationOptions; if (duration >= 0) { @@ -2603,8 +2626,21 @@ public: }); }; } + + if ([self.camera isEqualToMapCamera:camera]) + { + if (completion) + { + [self animateWithDelay:duration animations:^{ + completion(); + }]; + } + return; + } [self willChangeValueForKey:@"camera"]; + _mbglMap->cancelTransitions(); + mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera edgePadding:insets]; _mbglMap->flyTo(cameraOptions, animationOptions); [self didChangeValueForKey:@"camera"]; } |