From 491fce68790e05cd0a876815751dc5cb72a2761e Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Wed, 27 Feb 2019 19:58:20 +0200 Subject: [core] Added Map::pitchBy() --- include/mbgl/map/map.hpp | 3 +++ platform/glfw/glfw_view.cpp | 2 +- platform/qt/app/mapwindow.cpp | 2 +- platform/qt/include/qmapboxgl.hpp | 1 + platform/qt/src/qmapboxgl.cpp | 5 +++++ src/mbgl/map/map.cpp | 6 ++++++ 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 35821457fa..06772f2cd2 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -90,6 +90,9 @@ public: void setLatLngZoom(const LatLng&, double zoom, const EdgeInsets&, const AnimationOptions& = {}); void resetZoom(); + // Pitch + void pitchBy(double pitch, const AnimationOptions& animation = {}); + // Bounds void setLatLngBounds(optional); optional getLatLngBounds() const; diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index 2a1afdfe1e..78239bb97b 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -553,7 +553,7 @@ void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) { } else if (view->pitching) { const double dy = y - view->lastY; if (dy) { - view->map->setPitch(view->map->getPitch() - dy / 2); + view->map->pitchBy(dy / 2); } } view->lastX = x; diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp index 47dc1c8190..6171c8bf35 100644 --- a/platform/qt/app/mapwindow.cpp +++ b/platform/qt/app/mapwindow.cpp @@ -437,7 +437,7 @@ void MapWindow::mouseMoveEvent(QMouseEvent *ev) if (!delta.isNull()) { if (ev->buttons() == Qt::LeftButton && ev->modifiers() & Qt::ShiftModifier) { - m_map->setPitch(m_map->pitch() - delta.y()); + m_map->pitchBy(delta.y()); } else if (ev->buttons() == Qt::LeftButton) { m_map->moveBy(delta); } else if (ev->buttons() == Qt::RightButton) { diff --git a/platform/qt/include/qmapboxgl.hpp b/platform/qt/include/qmapboxgl.hpp index d29c9fc2c6..5309c58494 100644 --- a/platform/qt/include/qmapboxgl.hpp +++ b/platform/qt/include/qmapboxgl.hpp @@ -182,6 +182,7 @@ public: double pitch() const; void setPitch(double pitch); + void pitchBy(double pitch); NorthOrientation northOrientation() const; void setNorthOrientation(NorthOrientation); diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index e512b23901..cc4028b64d 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -885,6 +885,11 @@ void QMapboxGL::setPitch(double pitch_) d_ptr->mapObj->setPitch(pitch_); } +void QMapboxGL::pitchBy(double pitch_) +{ + d_ptr->mapObj->pitchBy(pitch_); +} + /*! Returns the north orientation mode. */ diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 25c4b5398d..ab4ccb2007 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -317,6 +317,12 @@ void Map::resetZoom() { setZoom(0); } +#pragma mark - Pitch + +void Map::pitchBy(double pitch, const AnimationOptions& animation) { + easeTo(CameraOptions().withPitch((impl->transform.getPitch() * util::RAD2DEG) - pitch), animation); +} + #pragma mark - Bounds optional Map::getLatLngBounds() const { -- cgit v1.2.1