summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2019-02-27 17:49:01 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2019-03-04 14:45:32 +0200
commit02f2b9c75c4031c084c177a582f18d3e888596fa (patch)
treef8ee3cb99c0ad7b14613373407df539bfeddf1d5
parent362231e2d02333e301b0ec70c85e5ac4e7741bf3 (diff)
downloadqtlocation-mapboxgl-02f2b9c75c4031c084c177a582f18d3e888596fa.tar.gz
[core] Added Map::scaleBy()
-rw-r--r--include/mbgl/map/map.hpp1
-rw-r--r--platform/glfw/glfw_view.cpp6
-rw-r--r--platform/qt/src/qmapboxgl.cpp2
-rw-r--r--src/mbgl/map/map.cpp5
4 files changed, 10 insertions, 4 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index fec67eb281..35821457fa 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -81,6 +81,7 @@ public:
void resetPosition(const EdgeInsets& = {});
// Zoom
+ void scaleBy(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation);
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/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp
index 97c4cde657..2a1afdfe1e 100644
--- a/platform/glfw/glfw_view.cpp
+++ b/platform/glfw/glfw_view.cpp
@@ -487,7 +487,7 @@ void GLFWView::onScroll(GLFWwindow *window, double /*xOffset*/, double yOffset)
scale = 1.0 / scale;
}
- view->map->setZoom(view->map->getZoom() + ::log2(scale), mbgl::ScreenCoordinate { view->lastX, view->lastY });
+ view->map->scaleBy(scale, mbgl::ScreenCoordinate { view->lastX, view->lastY });
}
void GLFWView::onWindowResize(GLFWwindow *window, int width, int height) {
@@ -530,9 +530,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->setZoom(view->map->getZoom() - 1, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
+ view->map->scaleBy(0.5, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
} else {
- view->map->setZoom(view->map->getZoom() + 1, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
+ view->map->scaleBy(2.0, mbgl::ScreenCoordinate { view->lastX, view->lastY }, mbgl::AnimationOptions{{mbgl::Milliseconds(500)}});
}
}
view->lastClick = now;
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 35ff7f7c29..e512b23901 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -1126,7 +1126,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->setZoom(d_ptr->mapObj->getZoom() + ::log2(scale_), mbgl::ScreenCoordinate { center.x(), center.y() });
+ d_ptr->mapObj->scaleBy(scale_, mbgl::ScreenCoordinate { center.x(), center.y() });
}
/*!
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 7c19375542..25c4b5398d 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -187,6 +187,11 @@ void Map::resetPosition(const EdgeInsets& padding) {
#pragma mark - Zoom
+void Map::scaleBy(double scale, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) {
+ double zoom = getZoom() + impl->transform.getState().scaleZoom(scale);
+ easeTo(CameraOptions().withZoom(zoom).withAnchor(anchor), animation);
+}
+
void Map::setZoom(double zoom, const AnimationOptions& animation) {
easeTo(CameraOptions().withZoom(zoom), animation);
}