[Qt] Use MapChangeWillStartLoadingMap to get notified about style changes
This commit is contained in:
@@ -28,6 +28,9 @@ public:
|
||||
void setValue(const QVariant &);
|
||||
QVariant value() const;
|
||||
|
||||
public slots:
|
||||
void checkUpdated();
|
||||
|
||||
signals:
|
||||
void layerChanged(const QString &);
|
||||
void propertyChanged(const QString &);
|
||||
@@ -36,7 +39,6 @@ signals:
|
||||
|
||||
protected:
|
||||
QQuickMapboxGLStyleProperty(QQuickItem *parent, Type);
|
||||
void checkUpdated();
|
||||
|
||||
QVariantMap m_map;
|
||||
};
|
||||
|
||||
@@ -277,6 +277,20 @@ ApplicationWindow {
|
||||
onClicked: waterColorDialog.open()
|
||||
}
|
||||
|
||||
Button {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
text: "Light style"
|
||||
onClicked: { mapStreets.style = "mapbox://styles/mapbox/light-v9" }
|
||||
}
|
||||
|
||||
Button {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
text: "Dark style"
|
||||
onClicked: { mapStreets.style = "mapbox://styles/mapbox/dark-v9" }
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
id: roadLabel
|
||||
anchors.left: parent.left
|
||||
|
||||
@@ -23,7 +23,9 @@ QQuickMapboxGL::~QQuickMapboxGL()
|
||||
|
||||
QQuickFramebufferObject::Renderer *QQuickMapboxGL::createRenderer() const
|
||||
{
|
||||
return new QQuickMapboxGLRenderer();
|
||||
QQuickMapboxGLRenderer *renderer = new QQuickMapboxGLRenderer();
|
||||
connect(renderer, SIGNAL(styleChanged()), this, SIGNAL(styleChanged()));
|
||||
return renderer;
|
||||
}
|
||||
|
||||
void QQuickMapboxGL::setPlugin(QDeclarativeGeoServiceProvider *)
|
||||
@@ -267,11 +269,13 @@ void QQuickMapboxGL::itemChange(QQuickItem::ItemChange change, const QQuickItem:
|
||||
case QQuickItem::ItemChildAddedChange:
|
||||
if (QQuickMapboxGLStyleProperty *property = qobject_cast<QQuickMapboxGLStyleProperty *>(value.item)) {
|
||||
connect(property, SIGNAL(updated(QVariantMap)), this, SLOT(onStylePropertyUpdated(QVariantMap)));
|
||||
connect(this, SIGNAL(styleChanged()), property, SLOT(checkUpdated()));
|
||||
}
|
||||
break;
|
||||
case QQuickItem::ItemChildRemovedChange:
|
||||
if (QQuickMapboxGLStyleProperty *property = qobject_cast<QQuickMapboxGLStyleProperty *>(value.item)) {
|
||||
disconnect(property, SIGNAL(updated(QVariantMap)), this, SLOT(onStylePropertyUpdated(QVariantMap)));
|
||||
disconnect(this, SIGNAL(styleChanged()), property, SLOT(checkUpdated()));
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -28,9 +28,24 @@ QQuickMapboxGLRenderer::~QQuickMapboxGLRenderer()
|
||||
|
||||
void QQuickMapboxGLRenderer::onMapChanged(QMapboxGL::MapChange change)
|
||||
{
|
||||
if (change == QMapboxGL::MapChangeDidFinishLoadingMap) {
|
||||
auto onMapChangeWillStartLoadingMap = [&]() {
|
||||
m_styleLoaded = false;
|
||||
};
|
||||
|
||||
auto onMapChangeDidFinishLoadingMap = [&]() {
|
||||
m_styleLoaded = true;
|
||||
update();
|
||||
emit styleChanged();
|
||||
};
|
||||
|
||||
switch (change) {
|
||||
case QMapboxGL::MapChangeWillStartLoadingMap:
|
||||
onMapChangeWillStartLoadingMap();
|
||||
break;
|
||||
case QMapboxGL::MapChangeDidFinishLoadingMap:
|
||||
onMapChangeDidFinishLoadingMap();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
|
||||
signals:
|
||||
void centerChanged(const QGeoCoordinate &);
|
||||
void styleChanged();
|
||||
|
||||
public slots:
|
||||
void onMapChanged(QMapboxGL::MapChange);
|
||||
|
||||
Reference in New Issue
Block a user