diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-05-02 17:51:05 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-05-02 19:33:54 +0300 |
commit | 91cdcbebf400a1cbee16ce9ef192b9223b276650 (patch) | |
tree | e3212a02eeddab49c889b843329124054d7dba03 /platform/qt | |
parent | d3f08f14421ec48113c53ffeac93728a692f0137 (diff) | |
download | qtlocation-mapboxgl-91cdcbebf400a1cbee16ce9ef192b9223b276650.tar.gz |
[Qt] Implement pan() method
Diffstat (limited to 'platform/qt')
-rw-r--r-- | platform/qt/include/qquickmapboxgl.hpp | 10 | ||||
-rw-r--r-- | platform/qt/src/qquickmapboxgl.cpp | 17 | ||||
-rw-r--r-- | platform/qt/src/qquickmapboxglrenderer.cpp | 4 |
3 files changed, 31 insertions, 0 deletions
diff --git a/platform/qt/include/qquickmapboxgl.hpp b/platform/qt/include/qquickmapboxgl.hpp index 0475bb4b39..023a27d5ff 100644 --- a/platform/qt/include/qquickmapboxgl.hpp +++ b/platform/qt/include/qquickmapboxgl.hpp @@ -4,6 +4,7 @@ #include <QGeoCoordinate> #include <QGeoServiceProvider> #include <QGeoShape> +#include <QPointF> #include <QQuickFramebufferObject> class QDeclarativeGeoServiceProvider; @@ -36,6 +37,7 @@ public: // QQuickFramebufferObject implementation. virtual Renderer *createRenderer() const Q_DECL_FINAL; + // Map QML Type interface implementation. void setPlugin(QDeclarativeGeoServiceProvider *plugin); QDeclarativeGeoServiceProvider *plugin() const; @@ -63,14 +65,20 @@ public: void setColor(const QColor &color); QColor color() const; + Q_INVOKABLE void pan(int dx, int dy); + + // MapboxGL QML Type interface. void setStyle(const QString &style); QString style() const; + QPointF swapPan(); + enum SyncState { NothingNeedsSync = 0x00, ZoomNeedsSync = 0x01, CenterNeedsSync = 0x02, StyleNeedsSync = 0x04, + PanNeedsSync = 0x08, }; int swapSyncState(); @@ -95,6 +103,8 @@ private: qreal m_maximumZoomLevel = 20; qreal m_zoomLevel = 20; + QPointF m_pan = QPointF(0, 0); + QGeoCoordinate m_center; QGeoShape m_visibleRegion; diff --git a/platform/qt/src/qquickmapboxgl.cpp b/platform/qt/src/qquickmapboxgl.cpp index 6b78c6312f..169c450ef7 100644 --- a/platform/qt/src/qquickmapboxgl.cpp +++ b/platform/qt/src/qquickmapboxgl.cpp @@ -159,6 +159,14 @@ QColor QQuickMapboxGL::color() const return QColor(); } +void QQuickMapboxGL::pan(int dx, int dy) +{ + m_pan += QPointF(dx, dy); + + m_syncState |= PanNeedsSync; + update(); +} + void QQuickMapboxGL::setStyle(const QString &styleUrl) { if (m_style == styleUrl) { @@ -178,6 +186,15 @@ QString QQuickMapboxGL::style() const return m_style; } +QPointF QQuickMapboxGL::swapPan() +{ + QPointF oldPan = m_pan; + + m_pan = QPointF(0, 0); + + return oldPan; +} + int QQuickMapboxGL::swapSyncState() { int oldState = m_syncState; diff --git a/platform/qt/src/qquickmapboxglrenderer.cpp b/platform/qt/src/qquickmapboxglrenderer.cpp index 20b5bf6d46..437a503e13 100644 --- a/platform/qt/src/qquickmapboxglrenderer.cpp +++ b/platform/qt/src/qquickmapboxglrenderer.cpp @@ -61,4 +61,8 @@ void QQuickMapboxGLRenderer::synchronize(QQuickFramebufferObject *item) if (syncStatus & QQuickMapboxGL::StyleNeedsSync) { m_map->setStyleURL(quickMap->style()); } + + if (syncStatus & QQuickMapboxGL::PanNeedsSync) { + m_map->moveBy(quickMap->swapPan()); + } } |