In C++ I can use QPainterPath::subtracted for drawing polygon with hole, but I don't know, how it's possible in QML Map.
It's possible to draw MapPolygon with a hole on Map in QML?
1.5k views Asked by Pavel At
2
There are 2 answers
0
On
The following QML code should work too, without the requirement for C++. Tested on Qt 6.5.
MapPolygon {
id: mapPoly
geoShape: QtPositioning.polygon(
[
QtPositioning.coordinate(51.11, 17.13),
QtPositioning.coordinate(50.42, 30.54),
QtPositioning.coordinate(58.36, 26.70)
],
[
[
QtPositioning.coordinate(54.36, 23.46),
QtPositioning.coordinate(51.91, 20.52),
QtPositioning.coordinate(51.50, 28.25),
QtPositioning.coordinate(54.36, 26.80)
]
]
)
Since Qt 5.13 is possible with the Mapbox GL Plugin, for example using a QGeoPolygon, you could also use GeoJSON. For example:
main.cpp
main.qml