summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2017-02-11 16:57:09 -0500
committerJason Wray <friedbunny@users.noreply.github.com>2017-02-13 18:35:04 -0500
commitd12ac71ba76c441e8dca97d0186abe4646a7d716 (patch)
tree82836cdd4002fdfd3c2b5899be0903c0043a6b17
parent235a06795acd8a8c084a778b19119c643bc3c931 (diff)
downloadqtlocation-mapboxgl-d12ac71ba76c441e8dca97d0186abe4646a7d716.tar.gz
[macos] Round non-freeform zoom gestures/commands to nearest integer
Affects: - Double-tap gestures - Two-finger tap gestures - +/- button pushes - Shortcut keys - Menu items and shortcut keys (in macapp)
-rw-r--r--platform/macos/CHANGELOG.md1
-rw-r--r--platform/macos/app/MapDocument.m4
-rw-r--r--platform/macos/src/MGLMapView.mm21
3 files changed, 21 insertions, 5 deletions
diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md
index b52d1d7055..87790f75c2 100644
--- a/platform/macos/CHANGELOG.md
+++ b/platform/macos/CHANGELOG.md
@@ -39,6 +39,7 @@
* Fixed flickering that occurred when panning past the antimeridian. ([#7574](https://github.com/mapbox/mapbox-gl-native/pull/7574))
* Added a method to MGLMapViewDelegate, `-mapView:shouldChangeFromCamera:toCamera:`, that you can implement to restrict which parts the user can navigate to using gestures. ([#5584](https://github.com/mapbox/mapbox-gl-native/pull/5584))
* Added a `MGLDistanceFormatter` class for formatting geographic distances. ([#7888](https://github.com/mapbox/mapbox-gl-native/pull/7888))
+* Zooming by double-tap, two-finger tap, zoom buttons, shortcut keys, or demo app menu items or shortcut keys now zooms to the nearest integer zoom level. ([#8027](https://github.com/mapbox/mapbox-gl-native/pull/8027))
## 0.3.1
diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m
index 6f63542527..2de189c856 100644
--- a/platform/macos/app/MapDocument.m
+++ b/platform/macos/app/MapDocument.m
@@ -217,11 +217,11 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
}
- (IBAction)zoomIn:(id)sender {
- [self.mapView setZoomLevel:self.mapView.zoomLevel + 1 animated:YES];
+ [self.mapView setZoomLevel:round(self.mapView.zoomLevel) + 1 animated:YES];
}
- (IBAction)zoomOut:(id)sender {
- [self.mapView setZoomLevel:self.mapView.zoomLevel - 1 animated:YES];
+ [self.mapView setZoomLevel:round(self.mapView.zoomLevel) - 1 animated:YES];
}
- (IBAction)snapToNorth:(id)sender {
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 3d5f71feb1..654ca84fd0 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -1042,7 +1042,22 @@ public:
}
- (void)zoomBy:(double)zoomDelta animated:(BOOL)animated {
- [self setZoomLevel:self.zoomLevel + zoomDelta animated:animated];
+ [self setZoomLevel:round(self.zoomLevel) + zoomDelta animated:animated];
+}
+
+- (void)zoomBy:(double)zoomDelta atPoint:(NSPoint)point animated:(BOOL)animated {
+ [self willChangeValueForKey:@"centerCoordinate"];
+ [self willChangeValueForKey:@"zoomLevel"];
+ double newZoom = round(self.zoomLevel) + zoomDelta;
+ MGLMapCamera *oldCamera = self.camera;
+ mbgl::ScreenCoordinate center(point.x, self.bounds.size.height - point.y);
+ _mbglMap->setZoom(newZoom, center, MGLDurationInSecondsFromTimeInterval(animated ? MGLAnimationDuration : 0));
+ if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
+ && ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:self.camera]) {
+ self.camera = oldCamera;
+ }
+ [self didChangeValueForKey:@"zoomLevel"];
+ [self didChangeValueForKey:@"centerCoordinate"];
}
- (void)scaleBy:(double)scaleFactor atPoint:(NSPoint)point animated:(BOOL)animated {
@@ -1500,7 +1515,7 @@ public:
_mbglMap->cancelTransitions();
NSPoint gesturePoint = [gestureRecognizer locationInView:self];
- [self scaleBy:2 atPoint:gesturePoint animated:YES];
+ [self zoomBy:1 atPoint:gesturePoint animated:YES];
}
- (void)smartMagnifyWithEvent:(NSEvent *)event {
@@ -1512,7 +1527,7 @@ public:
// Tap with two fingers (“right-click”) to zoom out on mice but not trackpads.
NSPoint gesturePoint = [self convertPoint:event.locationInWindow fromView:nil];
- [self scaleBy:0.5 atPoint:gesturePoint animated:YES];
+ [self zoomBy:-1 atPoint:gesturePoint animated:YES];
}
/// Rotate fingers to rotate.