[Qt] Implement pan() method
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user