[Qt] Implement bearing on the QML Mapbox Map type

This commit is contained in:
Thiago Marcos P. Santos
2016-05-02 19:14:54 +03:00
parent 91cdcbebf4
commit 41f63db98b
3 changed files with 34 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ class Q_DECL_EXPORT QQuickMapboxGL : public QQuickFramebufferObject
// MapboxGL QML Type interface.
Q_PROPERTY(QString style READ style WRITE setStyle NOTIFY styleChanged)
Q_PROPERTY(qreal bearing READ bearing WRITE setBearing NOTIFY bearingChanged)
public:
QQuickMapboxGL(QQuickItem *parent = 0);
@@ -71,6 +72,9 @@ public:
void setStyle(const QString &style);
QString style() const;
void setBearing(qreal bearing);
qreal bearing() const;
QPointF swapPan();
enum SyncState {
@@ -79,6 +83,7 @@ public:
CenterNeedsSync = 0x02,
StyleNeedsSync = 0x04,
PanNeedsSync = 0x08,
BearingNeedsSync = 0x16,
};
int swapSyncState();
@@ -97,6 +102,7 @@ signals:
void colorChanged(const QColor &color);
void styleChanged();
void bearingChanged(qreal angle);
private:
qreal m_minimumZoomLevel = 0;
@@ -109,6 +115,7 @@ private:
QGeoShape m_visibleRegion;
QString m_style;
qreal m_bearing = 0;
int m_syncState = NothingNeedsSync;
};

View File

@@ -6,6 +6,8 @@
#include <QString>
#include <QtGlobal>
#include <cmath>
QQuickMapboxGL::QQuickMapboxGL(QQuickItem *parent_)
: QQuickFramebufferObject(parent_)
{
@@ -186,6 +188,27 @@ QString QQuickMapboxGL::style() const
return m_style;
}
void QQuickMapboxGL::setBearing(qreal angle)
{
angle = std::fmod(angle, 360.);
if (m_bearing == angle) {
return;
}
m_bearing = angle;
m_syncState |= BearingNeedsSync;
update();
emit bearingChanged(m_bearing);
}
qreal QQuickMapboxGL::bearing() const
{
return m_bearing;
}
QPointF QQuickMapboxGL::swapPan()
{
QPointF oldPan = m_pan;

View File

@@ -65,4 +65,8 @@ void QQuickMapboxGLRenderer::synchronize(QQuickFramebufferObject *item)
if (syncStatus & QQuickMapboxGL::PanNeedsSync) {
m_map->moveBy(quickMap->swapPan());
}
if (syncStatus & QQuickMapboxGL::BearingNeedsSync) {
m_map->setBearing(quickMap->bearing());
}
}