summaryrefslogtreecommitdiff
path: root/platform/macos/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-04-11 13:30:03 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-04-13 10:28:44 -0700
commitf1c06f8d837b57c1b10677fb5317f0bf20987cf6 (patch)
treefe64a8ca383b76318f0ee10c778460f5a879b3ad /platform/macos/src
parenta2670336d4387782bb607092f3a06814bdf4eb8d (diff)
downloadqtlocation-mapboxgl-f1c06f8d837b57c1b10677fb5317f0bf20987cf6.tar.gz
[all] Remove redundant scale-related camera methods
We don't need to have two different measurement systems for map zoom.
Diffstat (limited to 'platform/macos/src')
-rw-r--r--platform/macos/src/MGLMapView.mm45
1 files changed, 13 insertions, 32 deletions
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 68a21b5666..56f003fcb0 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -157,7 +157,7 @@ public:
NSMagnificationGestureRecognizer *_magnificationGestureRecognizer;
NSRotationGestureRecognizer *_rotationGestureRecognizer;
NSClickGestureRecognizer *_singleClickRecognizer;
- double _scaleAtBeginningOfGesture;
+ double _zoomAtBeginningOfGesture;
CLLocationDirection _directionAtBeginningOfGesture;
CGFloat _pitchAtBeginningOfGesture;
BOOL _didHideCursorDuringGesture;
@@ -1037,31 +1037,12 @@ public:
[self didChangeValueForKey:@"zoomLevel"];
}
-- (void)zoomBy:(double)zoomDelta animated:(BOOL)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, MGLDurationFromTimeInterval(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 {
+- (void)setZoomLevel:(double)zoomLevel atPoint:(NSPoint)point animated:(BOOL)animated {
[self willChangeValueForKey:@"centerCoordinate"];
[self willChangeValueForKey:@"zoomLevel"];
MGLMapCamera *oldCamera = self.camera;
mbgl::ScreenCoordinate center(point.x, self.bounds.size.height - point.y);
- _mbglMap->scaleBy(scaleFactor, center, MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0));
+ _mbglMap->setZoom(zoomLevel, center, MGLDurationFromTimeInterval(animated ? MGLAnimationDuration : 0));
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:self.camera]) {
self.camera = oldCamera;
@@ -1402,10 +1383,10 @@ public:
_mbglMap->cancelTransitions();
if (gestureRecognizer.state == NSGestureRecognizerStateBegan) {
- _scaleAtBeginningOfGesture = _mbglMap->getScale();
+ _zoomAtBeginningOfGesture = _mbglMap->getZoom();
} else if (gestureRecognizer.state == NSGestureRecognizerStateChanged) {
- CGFloat newZoomLevel = log2f(_scaleAtBeginningOfGesture) - delta.y / 75;
- [self scaleBy:powf(2, newZoomLevel) / _mbglMap->getScale() atPoint:startPoint animated:NO];
+ CGFloat newZoomLevel = _zoomAtBeginningOfGesture - delta.y / 75;
+ [self setZoomLevel:newZoomLevel atPoint:startPoint animated:NO];
}
} else if (flags & NSAlternateKeyMask) {
// Option-drag to rotate and/or tilt.
@@ -1466,7 +1447,7 @@ public:
if (gestureRecognizer.state == NSGestureRecognizerStateBegan) {
_mbglMap->setGestureInProgress(true);
- _scaleAtBeginningOfGesture = _mbglMap->getScale();
+ _zoomAtBeginningOfGesture = _mbglMap->getZoom();
} else if (gestureRecognizer.state == NSGestureRecognizerStateChanged) {
NSPoint zoomInPoint = [gestureRecognizer locationInView:self];
mbgl::ScreenCoordinate center(zoomInPoint.x, self.bounds.size.height - zoomInPoint.y);
@@ -1474,7 +1455,7 @@ public:
[self willChangeValueForKey:@"zoomLevel"];
[self willChangeValueForKey:@"centerCoordinate"];
MGLMapCamera *oldCamera = self.camera;
- _mbglMap->setScale(_scaleAtBeginningOfGesture * (1 + gestureRecognizer.magnification), center);
+ _mbglMap->setZoom(_zoomAtBeginningOfGesture * (1 + gestureRecognizer.magnification), center);
if ([self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)]
&& ![self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:self.camera]) {
self.camera = oldCamera;
@@ -1526,7 +1507,7 @@ public:
_mbglMap->cancelTransitions();
NSPoint gesturePoint = [gestureRecognizer locationInView:self];
- [self zoomBy:1 atPoint:gesturePoint animated:YES];
+ [self setZoomLevel:round(self.zoomLevel) + 1 atPoint:gesturePoint animated:YES];
}
- (void)smartMagnifyWithEvent:(NSEvent *)event {
@@ -1538,7 +1519,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 zoomBy:-1 atPoint:gesturePoint animated:YES];
+ [self setZoomLevel:round(self.zoomLevel) - 1 atPoint:gesturePoint animated:YES];
}
/// Rotate fingers to rotate.
@@ -1591,7 +1572,7 @@ public:
}
NSPoint gesturePoint = [self convertPoint:event.locationInWindow fromView:nil];
- [self scaleBy:scale atPoint:gesturePoint animated:NO];
+ [self setZoomLevel:self.zoomLevel + log2(scale) atPoint:gesturePoint animated:NO];
}
}
} else if (self.scrollEnabled
@@ -1699,13 +1680,13 @@ public:
- (IBAction)moveToBeginningOfParagraph:(__unused id)sender {
if (self.zoomEnabled) {
- [self zoomBy:1 animated:YES];
+ [self setZoomLevel:round(self.zoomLevel) + 1 animated:YES];
}
}
- (IBAction)moveToEndOfParagraph:(__unused id)sender {
if (self.zoomEnabled) {
- [self zoomBy:-1 animated:YES];
+ [self setZoomLevel:round(self.zoomLevel) - 1 animated:YES];
}
}