diff options
author | xylosper <darklin20@gmail.com> | 2019-01-31 12:41:10 +0900 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2019-02-01 16:34:35 +0200 |
commit | b1ee903dc4e9b1855e89116b203b40b43a6422fa (patch) | |
tree | d817d7e9fc93f69cb4ed855a1e6dc18115c199ae /platform/qt | |
parent | 6b2f17191baccf7ff17ee912bdf04fb44bea6d52 (diff) | |
download | qtlocation-mapboxgl-b1ee903dc4e9b1855e89116b203b40b43a6422fa.tar.gz |
[qt] Add example of feature collection data for GeoJSON source
The example shows that both of QList<QMapbox::Feature> and
QVector<QMapbox::Feature> can be used as feature collection data
for GeoJSON layer.
Diffstat (limited to 'platform/qt')
-rw-r--r-- | platform/qt/app/mapwindow.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp index 551af4630b..47dc1c8190 100644 --- a/platform/qt/app/mapwindow.cpp +++ b/platform/qt/app/mapwindow.cpp @@ -346,6 +346,60 @@ void MapWindow::keyPressEvent(QKeyEvent *ev) } } break; + case Qt::Key_6: { + if (m_map->layerExists("innerCirclesLayer") || m_map->layerExists("outerCirclesLayer")) { + m_map->removeLayer("innerCirclesLayer"); + m_map->removeLayer("outerCirclesLayer"); + m_map->removeSource("innerCirclesSource"); + m_map->removeSource("outerCirclesSource"); + } else { + auto makePoint = [&] (double dx, double dy, const QString &color) { + auto coordinate = m_map->coordinate(); + coordinate.first += dx; + coordinate.second += dy; + return QMapbox::Feature{QMapbox::Feature::PointType, + {{{coordinate}}}, {{"color", color}}, {}}; + }; + + // multiple features by QVector<QMapbox::Feature> + QVector<QMapbox::Feature> inner{ + makePoint(0.001, 0, "red"), + makePoint(0, 0.001, "green"), + makePoint(0, -0.001, "blue") + }; + + m_map->addSource("innerCirclesSource", + {{"type", "geojson"}, {"data", QVariant::fromValue(inner)}}); + m_map->addLayer({ + {"id", "innerCirclesLayer"}, + {"type", "circle"}, + {"source", "innerCirclesSource"} + }); + + // multiple features by QList<QMapbox::Feature> + QList<QMapbox::Feature> outer{ + makePoint( 0.002, 0.002, "cyan"), + makePoint(-0.002, 0.002, "magenta"), + makePoint( 0.002, -0.002, "yellow"), + makePoint(-0.002, -0.002, "black") + }; + + m_map->addSource("outerCirclesSource", + {{"type", "geojson"}, {"data", QVariant::fromValue(outer)}}); + m_map->addLayer({ + {"id", "outerCirclesLayer"}, + {"type", "circle"}, + {"source", "outerCirclesSource"} + }); + + QVariantList getColor{"get", "color"}; + m_map->setPaintProperty("innerCirclesLayer", "circle-radius", 10.0); + m_map->setPaintProperty("innerCirclesLayer", "circle-color", getColor); + m_map->setPaintProperty("outerCirclesLayer", "circle-radius", 15.0); + m_map->setPaintProperty("outerCirclesLayer", "circle-color", getColor); + } + } + break; case Qt::Key_Tab: m_map->cycleDebugOptions(); break; |