summaryrefslogtreecommitdiff
path: root/examples/location/geojson_viewer/main.cpp
diff options
context:
space:
mode:
authorMatthias Rauter <matthias.rauter@qt.io>2023-02-21 11:48:13 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-02-22 12:54:37 +0000
commit0d7a0d92c64a906748b0676ea502ec3d6ccf27d0 (patch)
tree2f61236aa057fb82c2914ddf600ecffae61620ae /examples/location/geojson_viewer/main.cpp
parentf19a0b27d4945ef633ca6602d4af63abad88f134 (diff)
downloadqtlocation-0d7a0d92c64a906748b0676ea502ec3d6ccf27d0.tar.gz
Add drawing of mapItems to GeoJson viewer example
Pick-to: 6.5 Change-Id: I362acbb6a428e83c3490742824b54aa68890c47f Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples/location/geojson_viewer/main.cpp')
-rw-r--r--examples/location/geojson_viewer/main.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/examples/location/geojson_viewer/main.cpp b/examples/location/geojson_viewer/main.cpp
index 97364c3e..ba390c7d 100644
--- a/examples/location/geojson_viewer/main.cpp
+++ b/examples/location/geojson_viewer/main.cpp
@@ -75,8 +75,24 @@ public:
QVariantMap pt;
pt["type"] = "Point";
pt["data"] = QVariant::fromValue(mapCircle->geoShape());
- if (hasProperties(mapCircle))
- pt["properties"] = mapCircle->property("props").toMap();
+ QVariantMap propMap = mapCircle->property("props").toMap();
+ propMap["radius"] = mapCircle->radius();
+ pt["properties"] = propMap;
+ return pt;
+ }
+ static QVariantMap toVariant(QDeclarativeRectangleMapItem *mapRectangle)
+ {
+ QVariantMap pt;
+ pt["type"] = "Polygon";
+ QGeoRectangle rectanlge = mapRectangle->geoShape();
+ QGeoPolygon poly;
+ poly.addCoordinate(rectanlge.topLeft());
+ poly.addCoordinate(rectanlge.topRight());
+ poly.addCoordinate(rectanlge.bottomRight());
+ poly.addCoordinate(rectanlge.bottomLeft());
+ pt["data"] = QVariant::fromValue(poly);
+ if (hasProperties(mapRectangle))
+ pt["properties"] = mapRectangle->property("props").toMap();
return pt;
}
@@ -110,13 +126,19 @@ public:
entry = toVariant(polygon);
} else if (QDeclarativeCircleMapItem *circle = qobject_cast<QDeclarativeCircleMapItem *>(kid)) {
entry = toVariant(circle); // If GeoJSON Point type is visualized in other ways, handle those types here instead.
+ } else if (QDeclarativeRectangleMapItem *rectangle = qobject_cast<QDeclarativeRectangleMapItem *>(kid)) {
+ entry = toVariant(rectangle); // For the self-drawn rectangles. Will be exported as Polygons
+
}
features.append(entry);
}
- if (nodeType.isEmpty()) { // Dirty hack to handle (=skip) the first MIV used to process the fictitious list with 1 element
+ if (nodeType.isEmpty()) {
if (features.isEmpty())
return root;
- return features.first().toMap();
+ else if (features.size() == 1)
+ return features.first().toMap();
+ else
+ root["type"] = "FeatureCollection";
}
root["data"] = features;
return root;