[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.
This commit is contained in:
committed by
Thiago Marcos P. Santos
parent
6b2f17191b
commit
b1ee903dc4
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user