summaryrefslogtreecommitdiff
path: root/platform/macos/src
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-11-20 01:28:01 -0800
committerMinh Nguyễn <mxn@1ec5.org>2017-02-18 14:14:09 -0800
commitd790132eda070c652b1d3a6ac44dc5d7e66335f4 (patch)
tree9536dbea1399cc9bb0e0a1f22609f1da51896d61 /platform/macos/src
parent28ad35fc0461aa89b490e3b187fca5374f18596d (diff)
downloadqtlocation-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/macos/src')
-rw-r--r--platform/macos/src/MGLMapView.mm39
1 files changed, 27 insertions, 12 deletions
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 9cbc923271..e4a0c364da 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -1116,12 +1116,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];
mbgl::AnimationOptions animationOptions;
if (duration > 0) {
animationOptions.duration.emplace(MGLDurationInSeconds(duration));
@@ -1137,8 +1131,19 @@ public:
});
};
}
+
+ if ([self.camera isEqualToMapCamera:camera]) {
+ if (completion) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ completion();
+ });
+ }
+ return;
+ }
[self willChangeValueForKey:@"camera"];
+ _mbglMap->cancelTransitions();
+ mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera];
_mbglMap->easeTo(cameraOptions, animationOptions);
[self didChangeValueForKey:@"camera"];
}
@@ -1152,12 +1157,6 @@ public:
}
- (void)flyToCamera:(MGLMapCamera *)camera 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];
mbgl::AnimationOptions animationOptions;
if (duration >= 0) {
animationOptions.duration = MGLDurationInSeconds(duration);
@@ -1178,8 +1177,19 @@ public:
});
};
}
+
+ if ([self.camera isEqualToMapCamera:camera]) {
+ if (completion) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ completion();
+ });
+ }
+ return;
+ }
[self willChangeValueForKey:@"camera"];
+ _mbglMap->cancelTransitions();
+ mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera];
_mbglMap->flyTo(cameraOptions, animationOptions);
[self didChangeValueForKey:@"camera"];
}
@@ -1228,6 +1238,11 @@ public:
if (animated) {
animationOptions.duration = MGLDurationInSeconds(MGLAnimationDuration);
}
+
+ MGLMapCamera *camera = [self cameraForCameraOptions:cameraOptions];
+ if ([self.camera isEqualToMapCamera:camera]) {
+ return;
+ }
[self willChangeValueForKey:@"visibleCoordinateBounds"];
animationOptions.transitionFinishFn = ^() {