summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-12-14 23:14:50 -0800
committerMinh Nguyễn <mxn@1ec5.org>2015-12-15 12:52:13 -0800
commit9aba820892aed89b821304f559e1a72e5856cb5c (patch)
tree2a0bb53c2c182c52ae93b903c2cb522337b8a562
parente1854f0f2628e4808b48e01231c1a3a3a6cf9b68 (diff)
downloadqtlocation-mapboxgl-9aba820892aed89b821304f559e1a72e5856cb5c.tar.gz
[ios, osx] Added flyTo to OS X; refactored camera setters
-rw-r--r--include/mbgl/ios/MGLMapView.h2
-rw-r--r--include/mbgl/osx/MGLMapView.h10
-rw-r--r--platform/ios/MGLMapView.mm65
-rw-r--r--platform/osx/src/MGLMapView.mm73
4 files changed, 104 insertions, 46 deletions
diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h
index 2a5e649fef..e122874e37 100644
--- a/include/mbgl/ios/MGLMapView.h
+++ b/include/mbgl/ios/MGLMapView.h
@@ -218,8 +218,6 @@ IB_DESIGNABLE
* @param completion The block to execute after the animation finishes. */
- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion;
-#pragma mark - flyTo
-
/** Uses a ballistic parabolic motion to "fly" the viewpoint to a different location with respect to the map with an optional transition duration.
* @param camera The new viewpoint.
* @param duration The amount of time, measured in seconds, that the transition animation should take. Specify `0` to jump to the new viewpoint instantaneously.
diff --git a/include/mbgl/osx/MGLMapView.h b/include/mbgl/osx/MGLMapView.h
index 41f7e02c84..5241329f3d 100644
--- a/include/mbgl/osx/MGLMapView.h
+++ b/include/mbgl/osx/MGLMapView.h
@@ -249,6 +249,16 @@ IB_DESIGNABLE
@param completion The block to execute after the animation finishes. */
- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion;
+/** Uses a ballistic parabolic motion to “fly” the viewpoint to a different
+ location with respect to the map with an optional transition duration.
+
+ @param camera The new viewpoint.
+ @param duration The amount of time, measured in seconds, that the transition
+ animation should take. Specify `0` to jump to the new viewpoint
+ instantaneously.
+ @param completion The block to execute after the animation finishes. */
+- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion;
+
/** The geographic coordinate bounds visible in the receiver’s viewport.
Changing the value of this property updates the receiver immediately. If you
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index fefb77d112..83244372fb 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -1787,18 +1787,52 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion
{
- [self _setCamera:camera withDuration:duration animationTimingFunction:function completionHandler:completion useFly:NO];
+ _mbglMap->cancelTransitions();
+ mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
+ if (duration > 0)
+ {
+ options.duration = MGLDurationInSeconds(duration);
+ options.easing = MGLUnitBezierForMediaTimingFunction(function);
+ }
+ if (completion)
+ {
+ options.transitionFinishFn = [completion]() {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ completion();
+ });
+ };
+ }
+
+ [self willChangeValueForKey:@"camera"];
+ _mbglMap->easeTo(options);
+ [self didChangeValueForKey:@"camera"];
}
- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion
{
- [self _setCamera:camera withDuration:duration animationTimingFunction:nil completionHandler:completion useFly:YES];
-}
-
-- (void)_setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion useFly:(BOOL)fly
-{
_mbglMap->cancelTransitions();
+ mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
+ if (duration > 0)
+ {
+ options.duration = MGLDurationInSeconds(duration);
+ }
+ if (completion)
+ {
+ options.transitionFinishFn = [completion]() {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ completion();
+ });
+ };
+ }
+ [self willChangeValueForKey:@"camera"];
+ _mbglMap->flyTo(options);
+ [self didChangeValueForKey:@"camera"];
+}
+
+/// Returns a CameraOptions object that specifies parameters for animating to
+/// the given camera.
+- (mbgl::CameraOptions)cameraOptionsObjectForAnimatingToCamera:(MGLMapCamera *)camera {
// The opposite side is the distance between the center and one edge.
mbgl::LatLng centerLatLng = MGLLatLngFromLocationCoordinate2D(camera.centerCoordinate);
mbgl::ProjectedMeters centerMeters = _mbglMap->projectedMetersForLatLng(centerLatLng);
@@ -1855,24 +1889,7 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
{
options.pitch = pitch;
}
- if (duration > 0)
- {
- options.duration = MGLDurationInSeconds(duration);
- options.easing = MGLUnitBezierForMediaTimingFunction(function);
- }
- if (completion)
- {
- options.transitionFinishFn = [completion]() {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- completion();
- });
- };
- }
- if (fly) {
- _mbglMap->flyTo(options);
- } else {
- _mbglMap->easeTo(options);
- }
+ return options;
}
- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(nullable UIView *)view
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index bc7309aae5..40e37bac20 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -987,6 +987,53 @@ public:
- (void)setCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration animationTimingFunction:(nullable CAMediaTimingFunction *)function completionHandler:(nullable void (^)(void))completion {
_mbglMap->cancelTransitions();
+ mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
+ if (duration > 0) {
+ options.duration = MGLDurationInSeconds(duration);
+ options.easing = MGLUnitBezierForMediaTimingFunction(function);
+ }
+ if (completion) {
+ options.transitionFinishFn = [completion]() {
+ // Must run asynchronously after the transition is completely over.
+ // Otherwise, a call to -setCamera: within the completion handler
+ // would reenter the completion handler’s caller.
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ completion();
+ });
+ };
+ }
+
+ [self willChangeValueForKey:@"camera"];
+ _mbglMap->easeTo(options);
+ [self didChangeValueForKey:@"camera"];
+}
+
+- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration completionHandler:(nullable void (^)(void))completion {
+ _mbglMap->cancelTransitions();
+
+ mbgl::CameraOptions options = [self cameraOptionsObjectForAnimatingToCamera:camera];
+ if (duration > 0) {
+ options.duration = MGLDurationInSeconds(duration);
+ }
+ if (completion) {
+ options.transitionFinishFn = [completion]() {
+ // Must run asynchronously after the transition is completely over.
+ // Otherwise, a call to -setCamera: within the completion handler
+ // would reenter the completion handler’s caller.
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ completion();
+ });
+ };
+ }
+
+ [self willChangeValueForKey:@"camera"];
+ _mbglMap->flyTo(options);
+ [self didChangeValueForKey:@"camera"];
+}
+
+/// Returns a CameraOptions object that specifies parameters for animating to
+/// the given camera.
+- (mbgl::CameraOptions)cameraOptionsObjectForAnimatingToCamera:(MGLMapCamera *)camera {
// The opposite side is the distance between the center and one edge.
mbgl::LatLng centerLatLng = MGLLatLngFromLocationCoordinate2D(camera.centerCoordinate);
mbgl::ProjectedMeters centerMeters = _mbglMap->projectedMetersForLatLng(centerLatLng);
@@ -1037,24 +1084,7 @@ public:
if (pitch >= 0) {
options.pitch = pitch;
}
- if (duration > 0) {
- options.duration = MGLDurationInSeconds(duration);
- options.easing = MGLUnitBezierForMediaTimingFunction(function);
- }
- if (completion) {
- options.transitionFinishFn = [completion]() {
- // Must run asynchronously after the transition is completely over.
- // Otherwise, a call to -setCamera: within the completion handler
- // would reenter the completion handler’s caller.
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- completion();
- });
- };
- }
-
- [self willChangeValueForKey:@"camera"];
- _mbglMap->easeTo(options);
- [self didChangeValueForKey:@"camera"];
+ return options;
}
+ (NSSet *)keyPathsForValuesAffectingVisibleCoordinateBounds {
@@ -1215,7 +1245,7 @@ public:
/// Tap with two fingers (“right-click”) to zoom out.
- (void)handleSecondaryClickGesture:(NSClickGestureRecognizer *)gestureRecognizer {
- if (!self.zoomEnabled) {
+ if (!self.zoomEnabled || gestureRecognizer.state != NSGestureRecognizerStateEnded) {
return;
}
@@ -1227,7 +1257,7 @@ public:
/// Double-click or double-tap to zoom in.
- (void)handleDoubleClickGesture:(NSClickGestureRecognizer *)gestureRecognizer {
- if (!self.zoomEnabled) {
+ if (!self.zoomEnabled || gestureRecognizer.state != NSGestureRecognizerStateEnded) {
return;
}
@@ -2244,6 +2274,9 @@ public:
// main thread. OpenGL contexts and extensions are thread-local, so this
// has to happen on the Map thread too.
activate();
+
+// auto size = getFramebufferSize();
+// MBGL_CHECK_ERROR(glViewport(0, 0, size[0], size[1]));
}
void afterRender() override {