0

I want to draw a MapPolygon in QML based on some coordinates. I extract my coordinates from a file and put them in a QVariantList by the name of yellowPointsQML and send this QVariantList to QML. So I use these codes (these coordinates come from a file):

in *.cpp file:

yellowPoints.append(QVariant::fromValue(QGeoCoordinate(38.613931, 50.842588)));
yellowPoints.append(QVariant::fromValue(QGeoCoordinate(38.613489, 50.838962)));
yellowPoints.append(QVariant::fromValue(QGeoCoordinate(38.612465, 50.837600)));
yellowPoints.append(QVariant::fromValue(QGeoCoordinate(38.610743, 50.840475)));
yellowPoints.append(QVariant::fromValue(QGeoCoordinate(38.611564, 50.843286)));

and in *.qml

MapPolygon{
    id: yellowCover
    color: '#ffff6f'
    opacity: 0.7
}
...
yellowCover.path = yellowPointsQML

and every thing is OK and my polygon is convex. But if I change the sort of these coordinates, the result will be sloppy. Since in my input file I just have some coordinates without any order, so I don't know how can I set the order of the coordinates to drawing a convex polygon.

  • Actually, the question doesn't relates to QML. Shortly, you have to find center point and then sort each point according to the polar angle. See it [here](https://stackoverflow.com/questions/6989100/sort-points-in-clockwise-order). – folibis Jun 04 '18 at 13:07
  • @folibis thanks for your answer, I think there is no need to convert to polar angle, because latitude and longitude will get all of the location informations and compare them with the center point is the solution. – ahmadi morteza ali Jun 04 '18 at 15:52
  • @ahmadimortezaali The problem has nothing to do with QML, is a computational geometry problem: given n points get all the n-sided convex polygons whose vertices are those points. – eyllanesc Jun 04 '18 at 16:08
  • @eyllanesc thanks, I remove the `qml` tag. I thought may be there is an option in `MapPolygon` to do that automatically. – ahmadi morteza ali Jun 07 '18 at 09:00

0 Answers0