From b1ee903dc4e9b1855e89116b203b40b43a6422fa Mon Sep 17 00:00:00 2001 From: xylosper Date: Thu, 31 Jan 2019 12:41:10 +0900 Subject: [qt] Add example of feature collection data for GeoJSON source The example shows that both of QList and QVector can be used as feature collection data for GeoJSON layer. --- platform/qt/app/mapwindow.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) 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 + QVector 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 + QList 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; -- cgit v1.2.1