summaryrefslogtreecommitdiff
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
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.
-rw-r--r--include/mbgl/map/map.hpp5
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java8
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java55
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java4
-rwxr-xr-xplatform/android/src/native_map_view.cpp17
-rwxr-xr-xplatform/android/src/native_map_view.hpp6
-rw-r--r--platform/glfw/glfw_view.cpp6
-rw-r--r--platform/ios/src/MGLMapView.mm20
-rw-r--r--platform/macos/src/MGLMapView.mm45
-rw-r--r--platform/qt/src/qmapboxgl.cpp6
-rw-r--r--src/mbgl/map/map.cpp20
-rw-r--r--src/mbgl/map/transform.cpp46
-rw-r--r--src/mbgl/map/transform.hpp22
-rw-r--r--src/mbgl/map/transform_state.cpp4
-rw-r--r--src/mbgl/map/transform_state.hpp1
-rw-r--r--test/map/transform.test.cpp76
17 files changed, 74 insertions, 269 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index c39009c8da..c41bce6809 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -95,10 +95,7 @@ public:
LatLng getLatLng(const EdgeInsets& = {}) const;
void resetPosition(const EdgeInsets& = {});
- // Scale
- void scaleBy(double ds, optional<ScreenCoordinate> = {}, const AnimationOptions& = {});
- void setScale(double scale, optional<ScreenCoordinate> = {}, const AnimationOptions& = {});
- double getScale() const;
+ // Zoom
void setZoom(double zoom, const AnimationOptions& = {});
void setZoom(double zoom, optional<ScreenCoordinate>, const AnimationOptions& = {});
void setZoom(double zoom, const EdgeInsets&, const AnimationOptions& = {});
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java
index 67e55352f4..85f6dc7e0e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java
@@ -230,7 +230,7 @@ final class MapGestureDetector {
float scrollDist = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
// Scale the map by the appropriate power of two factor
- transform.zoomBy(Math.pow(2.0, scrollDist), event.getX(), event.getY());
+ transform.zoomBy(scrollDist, event.getX(), event.getY());
return true;
@@ -479,17 +479,17 @@ final class MapGestureDetector {
// Scale the map
if (focalPoint != null) {
// arround user provided focal point
- transform.zoomBy(detector.getScaleFactor(), focalPoint.x, focalPoint.y);
+ transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(2), focalPoint.x, focalPoint.y);
} else if (quickZoom) {
// clamp scale factors we feed to core #7514
float scaleFactor = MathUtils.clamp(detector.getScaleFactor(),
MapboxConstants.MINIMUM_SCALE_FACTOR_CLAMP,
MapboxConstants.MAXIMUM_SCALE_FACTOR_CLAMP);
// around center map
- transform.zoomBy(scaleFactor, uiSettings.getWidth() / 2, uiSettings.getHeight() / 2);
+ transform.zoomBy(Math.log(scaleFactor) / Math.log(2), uiSettings.getWidth() / 2, uiSettings.getHeight() / 2);
} else {
// around gesture
- transform.zoomBy(detector.getScaleFactor(), detector.getFocusX(), detector.getFocusY());
+ transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(2), detector.getFocusX(), detector.getFocusY());
}
return true;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
index a9dedcf7dc..6fd86eba45 100755
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
@@ -338,55 +338,6 @@ final class NativeMapView {
nativeSetPitch(pitch, duration);
}
- public void scaleBy(double ds) {
- if (isDestroyedOn("scaleBy")) {
- return;
- }
- scaleBy(ds, Double.NaN, Double.NaN);
- }
-
- public void scaleBy(double ds, double cx, double cy) {
- if (isDestroyedOn("scaleBy")) {
- return;
- }
- scaleBy(ds, cx, cy, 0);
- }
-
- public void scaleBy(double ds, double cx, double cy, long duration) {
- if (isDestroyedOn("scaleBy")) {
- return;
- }
- nativeScaleBy(ds, cx / pixelRatio, cy / pixelRatio, duration);
- }
-
- public void setScale(double scale) {
- if (isDestroyedOn("setScale")) {
- return;
- }
- setScale(scale, Double.NaN, Double.NaN);
- }
-
- public void setScale(double scale, double cx, double cy) {
- if (isDestroyedOn("setScale")) {
- return;
- }
- setScale(scale, cx, cy, 0);
- }
-
- public void setScale(double scale, double cx, double cy, long duration) {
- if (isDestroyedOn("setScale")) {
- return;
- }
- nativeSetScale(scale, cx / pixelRatio, cy / pixelRatio, duration);
- }
-
- public double getScale() {
- if (isDestroyedOn("getScale")) {
- return 0;
- }
- return nativeGetScale();
- }
-
public void setZoom(double zoom, PointF focalPoint, long duration) {
if (isDestroyedOn("setZoom")) {
return;
@@ -1025,12 +976,6 @@ final class NativeMapView {
private native void nativeSetPitch(double pitch, long duration);
- private native void nativeScaleBy(double ds, double cx, double cy, long duration);
-
- private native void nativeSetScale(double scale, double cx, double cy, long duration);
-
- private native double nativeGetScale();
-
private native void nativeSetZoom(double zoom, double cx, double cy, long duration);
private native double nativeGetZoom();
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
index 82d5dec6a0..ff466c436c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
@@ -125,6 +125,6 @@ public class Projection {
* @return zoom level that fits the MapView.
*/
public double calculateZoom(float minScale) {
- return Math.log(nativeMapView.getScale() * minScale) / Math.log(2);
+ return nativeMapView.getZoom() + Math.log(minScale) / Math.log(2);
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java
index 78a38c73b9..6bccf6204b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java
@@ -273,8 +273,8 @@ final class Transform implements MapView.OnMapChangedListener {
}
}
- void zoomBy(double pow, float x, float y) {
- mapView.scaleBy(pow, x, y);
+ void zoomBy(double z, float x, float y) {
+ mapView.setZoom(mapView.getZoom() + z, new PointF(x, y), 0);
}
void moveBy(double offsetX, double offsetY, long duration) {
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index c33998bf6d..78e021c321 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -466,20 +466,6 @@ void NativeMapView::setPitch(jni::JNIEnv&, jni::jdouble pitch, jni::jlong durati
map->setPitch(pitch, mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
}
-void NativeMapView::scaleBy(jni::JNIEnv&, jni::jdouble ds, jni::jdouble cx, jni::jdouble cy, jni::jlong duration) {
- mbgl::ScreenCoordinate center(cx, cy);
- map->scaleBy(ds, center, mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
-}
-
-void NativeMapView::setScale(jni::JNIEnv&, jni::jdouble scale, jni::jdouble cx, jni::jdouble cy, jni::jlong duration) {
- mbgl::ScreenCoordinate center(cx, cy);
- map->setScale(scale, center, mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
-}
-
-jni::jdouble NativeMapView::getScale(jni::JNIEnv&) {
- return map->getScale();
-}
-
void NativeMapView::setZoom(jni::JNIEnv&, jni::jdouble zoom, jni::jdouble x, jni::jdouble y, jni::jlong duration) {
map->setZoom(zoom, mbgl::ScreenCoordinate{x,y}, mbgl::AnimationOptions{mbgl::Milliseconds(duration)});
}
@@ -1509,9 +1495,6 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
METHOD(&NativeMapView::resetPosition, "nativeResetPosition"),
METHOD(&NativeMapView::getPitch, "nativeGetPitch"),
METHOD(&NativeMapView::setPitch, "nativeSetPitch"),
- METHOD(&NativeMapView::scaleBy, "nativeScaleBy"),
- METHOD(&NativeMapView::getScale, "nativeGetScale"),
- METHOD(&NativeMapView::setScale, "nativeSetScale"),
METHOD(&NativeMapView::getZoom, "nativeGetZoom"),
METHOD(&NativeMapView::setZoom, "nativeSetZoom"),
METHOD(&NativeMapView::resetZoom, "nativeResetZoom"),
diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp
index 341205cd09..d1794b3516 100755
--- a/platform/android/src/native_map_view.hpp
+++ b/platform/android/src/native_map_view.hpp
@@ -137,12 +137,6 @@ public:
void setPitch(jni::JNIEnv&, jni::jdouble, jni::jlong);
- void scaleBy(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jdouble, jni::jlong);
-
- void setScale(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jdouble, jni::jlong);
-
- jni::jdouble getScale(jni::JNIEnv&);
-
void setZoom(jni::JNIEnv&, jni::jdouble, jni::jdouble, jni::jdouble, jni::jlong);
jni::jdouble getZoom(jni::JNIEnv&);
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp
index 9e21476485..5e9083f503 100644
--- a/platform/glfw/glfw_view.cpp
+++ b/platform/glfw/glfw_view.cpp
@@ -367,7 +367,7 @@ void GLFWView::onScroll(GLFWwindow *window, double /*xOffset*/, double yOffset)
scale = 1.0 / scale;
}
- view->map->scaleBy(scale, mbgl::ScreenCoordinate { view->lastX, view->lastY });
+ view->map->setZoom(view->map->getZoom() + std::log2(scale), mbgl::ScreenCoordinate { view->lastX, view->lastY });
}
void GLFWView::onWindowResize(GLFWwindow *window, int width, int height) {
@@ -408,9 +408,9 @@ void GLFWView::onMouseClick(GLFWwindow *window, int button, int action, int modi
double now = glfwGetTime();
if (now - view->lastClick < 0.4 /* ms */) {
if (modifiers & GLFW_MOD_SHIFT) {
- view->map->scaleBy(0.5, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
+ view->map->setZoom(view->map->getZoom() - 1, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
} else {
- view->map->scaleBy(2.0, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
+ view->map->setZoom(view->map->getZoom() + 1, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
}
}
view->lastClick = now;
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index b4c9e9d2a7..5ae588d619 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -1264,7 +1264,7 @@ public:
{
[self trackGestureEvent:MGLEventGesturePinchStart forRecognizer:pinch];
- self.scale = _mbglMap->getScale();
+ self.scale = powf(2, _mbglMap->getZoom());
[self notifyGestureDidBegin];
}
@@ -1280,7 +1280,7 @@ public:
if (![self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
[self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
{
- _mbglMap->setScale(newScale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
+ _mbglMap->setZoom(zoom, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
}
// The gesture recognizer only reports the gesture’s current center
// point, so use the previous center point to anchor the transition.
@@ -1338,7 +1338,7 @@ public:
} else {
if (drift)
{
- _mbglMap->setScale(newScale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationFromTimeInterval(duration));
+ _mbglMap->setZoom(zoom, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y }, MGLDurationFromTimeInterval(duration));
}
}
@@ -1616,7 +1616,7 @@ public:
{
[self trackGestureEvent:MGLEventGestureQuickZoom forRecognizer:quickZoom];
- self.scale = _mbglMap->getScale();
+ self.scale = powf(2, _mbglMap->getZoom());
self.quickZoomStart = [quickZoom locationInView:quickZoom.view].y;
@@ -1633,18 +1633,12 @@ public:
CGPoint centerPoint = [self anchorPointForGesture:quickZoom];
MGLMapCamera *oldCamera = self.camera;
-
- double zoom = self.zoomLevel;
- double scale = powf(2, newZoom) / _mbglMap->getScale();
-
- double estimatedZoom = zoom * scale;
-
- MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:estimatedZoom aroundAnchorPoint:centerPoint];
+ MGLMapCamera *toCamera = [self cameraByZoomingToZoomLevel:newZoom aroundAnchorPoint:centerPoint];
if (![self.delegate respondsToSelector:@selector(mapView:shouldChangeFromCamera:toCamera:)] ||
[self.delegate mapView:self shouldChangeFromCamera:oldCamera toCamera:toCamera])
{
- _mbglMap->scaleBy(scale, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
+ _mbglMap->setZoom(newZoom, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
}
[self cameraIsChanging];
@@ -2407,7 +2401,7 @@ public:
{
centerPoint = self.userLocationAnnotationViewCenter;
}
- _mbglMap->scaleBy(scaleFactor, mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
+ _mbglMap->setZoom(_mbglMap->getZoom() + log2(scaleFactor), mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
[self unrotateIfNeededForGesture];
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, self.accessibilityValue);
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];
}
}
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 7cb0541a75..2f5b3d84db 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -565,12 +565,12 @@ void QMapboxGL::setLongitude(double longitude_)
*/
double QMapboxGL::scale() const
{
- return d_ptr->mapObj->getScale();
+ return std::pow(2.0, d_ptr->mapObj->getZoom());
}
void QMapboxGL::setScale(double scale_, const QPointF &center)
{
- d_ptr->mapObj->setScale(scale_, mbgl::ScreenCoordinate { center.x(), center.y() });
+ d_ptr->mapObj->setZoom(std::log2(scale_), mbgl::ScreenCoordinate { center.x(), center.y() });
}
/*!
@@ -1055,7 +1055,7 @@ void QMapboxGL::moveBy(const QPointF &offset)
can be used for implementing a pinch gesture.
*/
void QMapboxGL::scaleBy(double scale_, const QPointF &center) {
- d_ptr->mapObj->scaleBy(scale_, mbgl::ScreenCoordinate { center.x(), center.y() });
+ d_ptr->mapObj->setZoom(d_ptr->mapObj->getZoom() + std::log2(scale_), mbgl::ScreenCoordinate { center.x(), center.y() });
}
/*!
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 45b2f26568..19b1222f0e 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -532,23 +532,7 @@ void Map::resetPosition(const EdgeInsets& padding) {
}
-#pragma mark - Scale
-
-void Map::scaleBy(double ds, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- impl->transform.scaleBy(ds, anchor, animation);
- impl->onUpdate(Update::RecalculateStyle);
-}
-
-void Map::setScale(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- impl->cameraMutated = true;
- impl->transform.setScale(scale, anchor, animation);
- impl->onUpdate(Update::RecalculateStyle);
-}
-
-double Map::getScale() const {
- return impl->transform.getScale();
-}
+#pragma mark - Zoom
void Map::setZoom(double zoom, const AnimationOptions& animation) {
impl->cameraMutated = true;
@@ -620,7 +604,7 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const Ed
scaleY -= (padding.top + padding.bottom) / height;
minScale = util::min(scaleX, scaleY);
}
- double zoom = util::log2(getScale() * minScale);
+ double zoom = getZoom() + util::log2(minScale);
zoom = util::clamp(zoom, getMinZoom(), getMaxZoom());
// Calculate the center point of a virtual bounds that is extended in all directions by padding.
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index eab40a6ee5..67729f7fe2 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -384,52 +384,28 @@ ScreenCoordinate Transform::getScreenCoordinate(const EdgeInsets& padding) const
#pragma mark - Zoom
-void Transform::scaleBy(double ds, const AnimationOptions& animation) {
- scaleBy(ds, optional<ScreenCoordinate> {}, animation);
-}
-
-void Transform::scaleBy(double ds, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- if (std::isnan(ds)) return;
- double scale = util::clamp(state.scale * ds, state.min_scale, state.max_scale);
- setScale(scale, anchor, animation);
-}
-
void Transform::setZoom(double zoom, const AnimationOptions& animation) {
- setZoom(zoom, optional<ScreenCoordinate> {}, animation);
+ CameraOptions camera;
+ camera.zoom = zoom;
+ easeTo(camera, animation);
}
void Transform::setZoom(double zoom, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- setScale(state.zoomScale(zoom), anchor, animation);
+ CameraOptions camera;
+ camera.zoom = zoom;
+ camera.anchor = anchor;
+ easeTo(camera, animation);
}
void Transform::setZoom(double zoom, const EdgeInsets& padding, const AnimationOptions& animation) {
- setScale(state.zoomScale(zoom), padding, animation);
-}
-
-double Transform::getZoom() const {
- return state.getZoom();
-}
-
-double Transform::getScale() const {
- return state.scale;
-}
-
-void Transform::setScale(double scale, const AnimationOptions& animation) {
- setScale(scale, optional<ScreenCoordinate> {}, animation);
-}
-
-void Transform::setScale(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
- if (std::isnan(scale)) return;
CameraOptions camera;
- camera.zoom = state.scaleZoom(scale);
- camera.anchor = anchor;
+ camera.zoom = zoom;
+ if (!padding.isFlush()) camera.anchor = getScreenCoordinate(padding);
easeTo(camera, animation);
}
-void Transform::setScale(double scale, const EdgeInsets& padding, const AnimationOptions& animation) {
- optional<ScreenCoordinate> anchor;
- if (!padding.isFlush()) anchor = getScreenCoordinate(padding);
- setScale(scale, anchor, animation);
+double Transform::getZoom() const {
+ return state.getZoom();
}
#pragma mark - Bounds
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 993f8f2c5f..2c59a6c1aa 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -65,26 +65,6 @@ public:
// Zoom
- /** Scales the map, keeping the given point fixed within the view.
- @param ds The difference in scale factors to scale the map by. */
- void scaleBy(double ds, const AnimationOptions& = {});
- /** Scales the map, keeping the given point fixed within the view.
- @param ds The difference in scale factors to scale the map by.
- @param anchor A point relative to the top-left corner of the view.
- If unspecified, the center point is fixed within the view. */
- void scaleBy(double ds, optional<ScreenCoordinate> anchor, const AnimationOptions& = {});
- /** Sets the scale factor, keeping the given point fixed within the view.
- @param scale The new scale factor. */
- void setScale(double scale, const AnimationOptions& = {});
- /** Sets the scale factor, keeping the given point fixed within the view.
- @param scale The new scale factor.
- @param anchor A point relative to the top-left corner of the view.
- If unspecified, the center point is fixed within the view. */
- void setScale(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& = {});
- /** Sets the scale factor, keeping the center point fixed within the inset view.
- @param scale The new scale factor.
- @param padding The viewport padding that affects the fixed center point. */
- void setScale(double scale, const EdgeInsets& padding, const AnimationOptions& = {});
/** Sets the zoom level, keeping the given point fixed within the view.
@param zoom The new zoom level. */
void setZoom(double zoom, const AnimationOptions& = {});
@@ -99,8 +79,6 @@ public:
void setZoom(double zoom, const EdgeInsets& padding, const AnimationOptions& = {});
/** Returns the zoom level. */
double getZoom() const;
- /** Returns the scale factor. */
- double getScale() const;
// Angle
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index f1c59533ae..fe90d4b2e4 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -136,10 +136,6 @@ double TransformState::getZoomFraction() const {
return getZoom() - getIntegerZoom();
}
-double TransformState::getScale() const {
- return scale;
-}
-
#pragma mark - Bounds
void TransformState::setLatLngBounds(const LatLngBounds& bounds_) {
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index 174aaa7ee6..85d5d96700 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -45,7 +45,6 @@ public:
double pixel_y() const;
// Zoom
- double getScale() const;
double getZoom() const;
int32_t getIntegerZoom() const;
double getZoomFraction() const;
diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp
index 69e3eb7c64..8a86598a1d 100644
--- a/test/map/transform.test.cpp
+++ b/test/map/transform.test.cpp
@@ -5,43 +5,29 @@
using namespace mbgl;
-TEST(Transform, InvalidScale) {
+TEST(Transform, InvalidZoom) {
Transform transform;
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
- ASSERT_DOUBLE_EQ(1, transform.getScale());
+ ASSERT_DOUBLE_EQ(0, transform.getZoom());
- transform.setScale(2 << 0);
-
- ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
- ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
- ASSERT_DOUBLE_EQ(2, transform.getScale());
+ transform.setZoom(1);
+ ASSERT_DOUBLE_EQ(1, transform.getZoom());
const double invalid = std::nan("");
- transform.setScale(invalid);
-
- ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
- ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
- ASSERT_DOUBLE_EQ(2, transform.getScale());
-
- transform.scaleBy(invalid);
-
- ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
- ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
- ASSERT_DOUBLE_EQ(2, transform.getScale());
transform.setZoom(invalid);
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
- ASSERT_DOUBLE_EQ(2, transform.getScale());
+ ASSERT_DOUBLE_EQ(1, transform.getZoom());
transform.setLatLngZoom({ 0, 0 }, invalid);
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
- ASSERT_DOUBLE_EQ(2, transform.getScale());
+ ASSERT_DOUBLE_EQ(1, transform.getZoom());
}
@@ -50,14 +36,14 @@ TEST(Transform, InvalidBearing) {
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
- ASSERT_DOUBLE_EQ(1, transform.getScale());
+ ASSERT_DOUBLE_EQ(0, transform.getZoom());
- transform.setScale(2 << 0);
+ transform.setZoom(1);
transform.setAngle(2);
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
- ASSERT_DOUBLE_EQ(2, transform.getScale());
+ ASSERT_DOUBLE_EQ(1, transform.getZoom());
ASSERT_DOUBLE_EQ(2, transform.getAngle());
const double invalid = std::nan("");
@@ -65,7 +51,7 @@ TEST(Transform, InvalidBearing) {
ASSERT_DOUBLE_EQ(0, transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(0, transform.getLatLng().longitude());
- ASSERT_DOUBLE_EQ(2, transform.getScale());
+ ASSERT_DOUBLE_EQ(1, transform.getZoom());
ASSERT_DOUBLE_EQ(2, transform.getAngle());
}
@@ -73,15 +59,7 @@ TEST(Transform, IntegerZoom) {
Transform transform;
auto checkIntegerZoom = [&transform](uint8_t zoomInt, double zoom) {
- double scale = transform.getState().zoomScale(zoom);
- transform.setScale(scale);
-#if __ANDROID__
- // Android uses log(x) / M_LN2 instead of log2(x) because the latter
- // is _broken in ARMv5 - that approach being less precise than log2(x).
- ASSERT_NEAR(transform.getScale(), scale, 0.0001);
-#else
- ASSERT_DOUBLE_EQ(transform.getScale(), scale);
-#endif
+ transform.setZoom(zoom);
ASSERT_NEAR(transform.getZoom(), zoom, 0.0001);
ASSERT_EQ(transform.getState().getIntegerZoom(), zoomInt);
ASSERT_NEAR(transform.getState().getZoomFraction(), zoom - zoomInt, 0.0001);
@@ -103,7 +81,7 @@ TEST(Transform, PerspectiveProjection) {
Transform transform;
transform.resize({ 1000, 1000 });
- transform.setScale(2 << 9);
+ transform.setZoom(10);
transform.setPitch(0.9);
transform.setLatLng(LatLng(38, -77));
@@ -133,7 +111,7 @@ TEST(Transform, PerspectiveProjection) {
TEST(Transform, UnwrappedLatLng) {
Transform transform;
transform.resize({ 1000, 1000 });
- transform.setScale(2 << 9);
+ transform.setZoom(10);
transform.setPitch(0.9);
transform.setLatLng(LatLng(38, -77));
@@ -165,7 +143,7 @@ TEST(Transform, ConstrainHeightOnly) {
Transform transform;
transform.resize({ 1000, 1000 });
- transform.setScale(std::pow(2, util::MAX_ZOOM));
+ transform.setZoom(util::MAX_ZOOM);
transform.setLatLng(LatLngBounds::world().southwest());
loc = transform.getLatLng();
@@ -183,7 +161,7 @@ TEST(Transform, ConstrainWidthAndHeight) {
Transform transform(MapObserver::nullObserver(), ConstrainMode::WidthAndHeight);
transform.resize({ 1000, 1000 });
- transform.setScale(std::pow(2, util::MAX_ZOOM));
+ transform.setZoom(util::MAX_ZOOM);
transform.setLatLng(LatLngBounds::world().southwest());
loc = transform.getLatLng();
@@ -216,34 +194,34 @@ TEST(Transform, Anchor) {
ASSERT_NE(latLng.longitude(), anchorLatLng.longitude());
transform.setLatLngZoom(latLng, 2);
- transform.scaleBy(1);
- ASSERT_DOUBLE_EQ(4, transform.getScale());
+ transform.setZoom(3);
+ ASSERT_DOUBLE_EQ(3, transform.getZoom());
ASSERT_DOUBLE_EQ(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude());
- transform.scaleBy(1.5, invalidAnchorPoint);
- ASSERT_DOUBLE_EQ(6, transform.getScale());
+ transform.setZoom(3.5, invalidAnchorPoint);
+ ASSERT_DOUBLE_EQ(3.5, transform.getZoom());
ASSERT_DOUBLE_EQ(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_DOUBLE_EQ(latLng.longitude(), transform.getLatLng().longitude());
- transform.scaleBy(2, anchorPoint);
- ASSERT_DOUBLE_EQ(12, transform.getScale());
+ transform.setZoom(5.5, anchorPoint);
+ ASSERT_DOUBLE_EQ(5.5, transform.getZoom());
ASSERT_NE(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_NE(latLng.longitude(), transform.getLatLng().longitude());
transform.setLatLngZoom(latLng, 10);
- transform.setScale(2 << 2);
- ASSERT_DOUBLE_EQ(2 << 2, transform.getScale());
+ transform.setZoom(3);
+ ASSERT_DOUBLE_EQ(3, transform.getZoom());
ASSERT_NEAR(latLng.latitude(), transform.getLatLng().latitude(), 0.000001);
ASSERT_NEAR(latLng.longitude(), transform.getLatLng().longitude(), 0.000001);
- transform.setScale(2 << 4, invalidAnchorPoint);
- ASSERT_DOUBLE_EQ(2 << 4, transform.getScale());
+ transform.setZoom(5, invalidAnchorPoint);
+ ASSERT_DOUBLE_EQ(5, transform.getZoom());
ASSERT_NEAR(latLng.latitude(), transform.getLatLng().latitude(), 0.000001);
ASSERT_NEAR(latLng.longitude(), transform.getLatLng().longitude(), 0.000001);
- transform.setScale(2 << 6, anchorPoint);
- ASSERT_DOUBLE_EQ(2 << 6, transform.getScale());
+ transform.setZoom(7, anchorPoint);
+ ASSERT_DOUBLE_EQ(7, transform.getZoom());
ASSERT_NE(latLng.latitude(), transform.getLatLng().latitude());
ASSERT_NE(latLng.longitude(), transform.getLatLng().longitude());