diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2017-05-11 20:28:01 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2017-05-25 12:56:29 +0000 |
commit | 2244429e7577baee4de062756d0708b076c1541f (patch) | |
tree | be7bb8202b020a03ad6ddf02fd5da34c4ac28a9a | |
parent | cc635fed31046c2fac37a1a2c90885efbfed819a (diff) | |
download | qtlocation-2244429e7577baee4de062756d0708b076c1541f.tar.gz |
Make it possible to MapItems to rendered under some style layers
Add a MapParamter to specify the default "before" layer for MapItems
that Mapbox GL can render. This can be used for inserting route lines
before labels.
Change-Id: I3ee414ee8af31f38b74c95b3ecc31df6085bed30
Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
8 files changed, 40 insertions, 9 deletions
diff --git a/src/location/doc/src/plugins/mapboxgl.qdoc b/src/location/doc/src/plugins/mapboxgl.qdoc index a412548e..4084e4c6 100644 --- a/src/location/doc/src/plugins/mapboxgl.qdoc +++ b/src/location/doc/src/plugins/mapboxgl.qdoc @@ -128,6 +128,14 @@ The following table lists optional parameters that can be passed to the Mapbox p experimental, and it does not support QQuickItem transformations nor stencil clipping. It might be also produce rendering artifacts e.g. when adding it inside a \l{QtQuick::Flipable}{Flipable} item. +\row + \li mapboxgl.mapping.items.insert_before + \li Some map items such as \l{QtLocation::MapPolyline}{MapPolyline}, + \l{QtLocation::MapPolygon}{MapPolygon} and \l{QtLocation::MapRectangle}{MapRectangle} + will be rendered after the topmost \l {https://www.mapbox.com/mapbox-gl-js/style-spec/#layers}{layer} + of the style. With this parameter set, the map items will be rendered \b before the layer ID + specified, unless the layer is not present on the current style, which will fallback + to the default behavior. This parameter can be used to display route lines under labels. \endtable \section2 Optional map parameters @@ -166,7 +174,7 @@ replacing the dash with camel case for technical reasons (i.e. \b line-cap will \li layer \li Adds a new \l {https://www.mapbox.com/mapbox-gl-js/style-spec/#layers}{style layer} to the map. On a Mapbox GL map, layers are used in styles for adding styling rules to specific subsets of data. A layer will contain a reference to the - data for which they are defining a style. + data for which they are defining a style. Use the \b before attribute to insert a layer before an existing layer. \row \li paint \li Defines how a layer will be painted. \l {https://www.mapbox.com/mapbox-gl-js/style-spec/#layer-paint}{Paint} properties @@ -218,6 +226,10 @@ Map { property var name: "route" property var layerType: "line" property var source: "routeSource" + + // Draw under the first road label layer + // of the mapbox-streets style. + property var before: "road-label-small" } MapParameter { diff --git a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp index 563c84f2..82378f0a 100644 --- a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp +++ b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp @@ -210,7 +210,7 @@ void QGeoMapMapboxGLPrivate::addMapItem(QDeclarativeGeoMapItemBase *item) QObject::connect(item, &QDeclarativeGeoMapItemBase::mapItemOpacityChanged, q, &QGeoMapMapboxGL::onMapItemPropertyChanged); - m_styleChanges << QMapboxGLStyleChange::addMapItem(item); + m_styleChanges << QMapboxGLStyleChange::addMapItem(item, m_mapItemsBefore); emit q->sgNodeChanged(); } @@ -342,6 +342,12 @@ void QGeoMapMapboxGL::setUseFBO(bool useFBO) d->m_useFBO = useFBO; } +void QGeoMapMapboxGL::setMapItemsBefore(const QString &before) +{ + Q_D(QGeoMapMapboxGL); + d->m_mapItemsBefore = before; +} + QSGNode *QGeoMapMapboxGL::updateSceneGraph(QSGNode *oldNode, QQuickWindow *window) { Q_D(QGeoMapMapboxGL); @@ -362,7 +368,7 @@ void QGeoMapMapboxGL::onMapChanged(QMapboxGL::MapChange change) d->m_styleChanges << QMapboxGLStyleChange::addMapParameter(param); for (QDeclarativeGeoMapItemBase *item : d->m_mapItems) - d->m_styleChanges << QMapboxGLStyleChange::addMapItem(item); + d->m_styleChanges << QMapboxGLStyleChange::addMapItem(item, d->m_mapItemsBefore); } } diff --git a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.h b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.h index 56b97e99..73cfd75a 100644 --- a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.h +++ b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.h @@ -56,6 +56,7 @@ public: QString copyrightsStyleSheet() const Q_DECL_OVERRIDE; void setMapboxGLSettings(const QMapboxGLSettings &); void setUseFBO(bool); + void setMapItemsBefore(const QString &); private Q_SLOTS: // QMapboxGL diff --git a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h index 15e5d167..598c9078 100644 --- a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h +++ b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl_p.h @@ -79,6 +79,7 @@ public: QMapboxGLSettings m_settings; bool m_useFBO = true; bool m_developmentMode = false; + QString m_mapItemsBefore; QTimer m_refresh; bool m_shouldRefresh = true; diff --git a/src/plugins/geoservices/mapboxgl/qgeomappingmanagerenginemapboxgl.cpp b/src/plugins/geoservices/mapboxgl/qgeomappingmanagerenginemapboxgl.cpp index 0535bf96..211c0bba 100644 --- a/src/plugins/geoservices/mapboxgl/qgeomappingmanagerenginemapboxgl.cpp +++ b/src/plugins/geoservices/mapboxgl/qgeomappingmanagerenginemapboxgl.cpp @@ -138,6 +138,10 @@ QGeoMappingManagerEngineMapboxGL::QGeoMappingManagerEngineMapboxGL(const QVarian m_useFBO = parameters.value(QStringLiteral("mapboxgl.mapping.use_fbo")).toBool(); } + if (parameters.contains(QStringLiteral("mapboxgl.mapping.items.insert_before"))) { + m_mapItemsBefore = parameters.value(QStringLiteral("mapboxgl.mapping.items.insert_before")).toString(); + } + engineInitialized(); } @@ -150,6 +154,7 @@ QGeoMap *QGeoMappingManagerEngineMapboxGL::createMap() QGeoMapMapboxGL* map = new QGeoMapMapboxGL(this, 0); map->setMapboxGLSettings(m_settings); map->setUseFBO(m_useFBO); + map->setMapItemsBefore(m_mapItemsBefore); return map; } diff --git a/src/plugins/geoservices/mapboxgl/qgeomappingmanagerenginemapboxgl.h b/src/plugins/geoservices/mapboxgl/qgeomappingmanagerenginemapboxgl.h index c5923cda..44096e60 100644 --- a/src/plugins/geoservices/mapboxgl/qgeomappingmanagerenginemapboxgl.h +++ b/src/plugins/geoservices/mapboxgl/qgeomappingmanagerenginemapboxgl.h @@ -59,6 +59,7 @@ public: private: QMapboxGLSettings m_settings; bool m_useFBO = true; + QString m_mapItemsBefore; }; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp index eccc64b8..8229b784 100644 --- a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp +++ b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp @@ -175,7 +175,7 @@ QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleChange::addMapParamete return changes; } -QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleChange::addMapItem(QDeclarativeGeoMapItemBase *item) +QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleChange::addMapItem(QDeclarativeGeoMapItemBase *item, const QString &before) { QList<QSharedPointer<QMapboxGLStyleChange>> changes; @@ -191,7 +191,7 @@ QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleChange::addMapItem(QDe QMapbox::Feature feature = featureFromMapItem(item); - changes << QMapboxGLStyleAddLayer::fromFeature(feature); + changes << QMapboxGLStyleAddLayer::fromFeature(feature, before); changes << QMapboxGLStyleAddSource::fromFeature(feature); changes << QMapboxGLStyleSetPaintProperty::fromMapItem(item); changes << QMapboxGLStyleSetLayoutProperty::fromMapItem(item); @@ -390,7 +390,7 @@ QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleSetPaintProperty::from void QMapboxGLStyleAddLayer::apply(QMapboxGL *map) { - map->addLayer(m_params); + map->addLayer(m_params, m_before); } QSharedPointer<QMapboxGLStyleChange> QMapboxGLStyleAddLayer::fromMapParameter(QGeoMapParameter *param) @@ -406,10 +406,12 @@ QSharedPointer<QMapboxGLStyleChange> QMapboxGLStyleAddLayer::fromMapParameter(QG layer->m_params[QStringLiteral("source-layer")] = param->property("sourceLayer"); } + layer->m_before = param->property("before").toString(); + return QSharedPointer<QMapboxGLStyleChange>(layer); } -QSharedPointer<QMapboxGLStyleChange> QMapboxGLStyleAddLayer::fromFeature(const QMapbox::Feature &feature) +QSharedPointer<QMapboxGLStyleChange> QMapboxGLStyleAddLayer::fromFeature(const QMapbox::Feature &feature, const QString &before) { auto layer = new QMapboxGLStyleAddLayer(); layer->m_params[QStringLiteral("id")] = feature.id; @@ -427,6 +429,8 @@ QSharedPointer<QMapboxGLStyleChange> QMapboxGLStyleAddLayer::fromFeature(const Q break; } + layer->m_before = before; + return QSharedPointer<QMapboxGLStyleChange>(layer); } diff --git a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h index a380660b..9164591a 100644 --- a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h +++ b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h @@ -58,7 +58,7 @@ public: virtual ~QMapboxGLStyleChange() = default; static QList<QSharedPointer<QMapboxGLStyleChange>> addMapParameter(QGeoMapParameter *); - static QList<QSharedPointer<QMapboxGLStyleChange>> addMapItem(QDeclarativeGeoMapItemBase *); + static QList<QSharedPointer<QMapboxGLStyleChange>> addMapItem(QDeclarativeGeoMapItemBase *, const QString &before); static QList<QSharedPointer<QMapboxGLStyleChange>> removeMapItem(QDeclarativeGeoMapItemBase *); virtual void apply(QMapboxGL *map) = 0; @@ -109,7 +109,7 @@ class QMapboxGLStyleAddLayer : public QMapboxGLStyleChange { public: static QSharedPointer<QMapboxGLStyleChange> fromMapParameter(QGeoMapParameter *); - static QSharedPointer<QMapboxGLStyleChange> fromFeature(const QMapbox::Feature &feature); + static QSharedPointer<QMapboxGLStyleChange> fromFeature(const QMapbox::Feature &feature, const QString &before); void apply(QMapboxGL *map) Q_DECL_OVERRIDE; @@ -117,6 +117,7 @@ private: QMapboxGLStyleAddLayer() = default; QVariantMap m_params; + QString m_before; }; class QMapboxGLStyleRemoveLayer : public QMapboxGLStyleChange |