diff options
Diffstat (limited to 'src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp')
-rw-r--r-- | src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp index 2d3850e1..70502e70 100644 --- a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp +++ b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp @@ -62,13 +62,24 @@ QString getId(QDeclarativeGeoMapItemBase *mapItem) return QStringLiteral("QDeclarativeGeoMapItemBase-") + QString::number(quint64(mapItem)); } +// Mapbox GL supports geometry segments that spans above 180 degrees in +// longitude. To keep visual expectations in parity with Qt, we need to adapt +// the coordinates to always use the shortest path when in ambiguity. +bool geoRectangleCrossesDateLine(const QGeoRectangle &rect) { + return rect.topLeft().longitude() > rect.bottomRight().longitude(); +} + QMapbox::Feature featureFromMapRectangle(QDeclarativeRectangleMapItem *mapItem) { const QGeoRectangle *rect = static_cast<const QGeoRectangle *>(&mapItem->geoShape()); QMapbox::Coordinate bottomLeft { rect->bottomLeft().latitude(), rect->bottomLeft().longitude() }; - QMapbox::Coordinate bottomRight { rect->bottomRight().latitude(), rect->bottomRight().longitude() }; QMapbox::Coordinate topLeft { rect->topLeft().latitude(), rect->topLeft().longitude() }; + QMapbox::Coordinate bottomRight { rect->bottomRight().latitude(), rect->bottomRight().longitude() }; QMapbox::Coordinate topRight { rect->topRight().latitude(), rect->topRight().longitude() }; + if (geoRectangleCrossesDateLine(*rect)) { + bottomRight.second += 360.0; + topRight.second += 360.0; + } QMapbox::CoordinatesCollections geometry { { { bottomLeft, bottomRight, topRight, topLeft, bottomLeft } } }; return QMapbox::Feature(QMapbox::Feature::PolygonType, geometry, {}, getId(mapItem)); @@ -78,8 +89,13 @@ QMapbox::Feature featureFromMapPolygon(QDeclarativePolygonMapItem *mapItem) { const QGeoPath *path = static_cast<const QGeoPath *>(&mapItem->geoShape()); QMapbox::Coordinates coordinates; + const bool crossesDateline = geoRectangleCrossesDateLine(path->boundingGeoRectangle()); for (const QGeoCoordinate &coordinate : path->path()) { - coordinates << QMapbox::Coordinate { coordinate.latitude(), coordinate.longitude() }; + if (!coordinates.empty() && crossesDateline && qAbs(coordinate.longitude() - coordinates.last().second) > 180.0) { + coordinates << QMapbox::Coordinate { coordinate.latitude(), coordinate.longitude() + (coordinate.longitude() >= 0 ? -360.0 : 360.0) }; + } else { + coordinates << QMapbox::Coordinate { coordinate.latitude(), coordinate.longitude() }; + } } coordinates.append(coordinates.first()); QMapbox::CoordinatesCollections geometry { { coordinates } }; @@ -91,8 +107,13 @@ QMapbox::Feature featureFromMapPolyline(QDeclarativePolylineMapItem *mapItem) { const QGeoPath *path = static_cast<const QGeoPath *>(&mapItem->geoShape()); QMapbox::Coordinates coordinates; + const bool crossesDateline = geoRectangleCrossesDateLine(path->boundingGeoRectangle()); for (const QGeoCoordinate &coordinate : path->path()) { - coordinates << QMapbox::Coordinate { coordinate.latitude(), coordinate.longitude() }; + if (!coordinates.empty() && crossesDateline && qAbs(coordinate.longitude() - coordinates.last().second) > 180.0) { + coordinates << QMapbox::Coordinate { coordinate.latitude(), coordinate.longitude() + (coordinate.longitude() >= 0 ? -360.0 : 360.0) }; + } else { + coordinates << QMapbox::Coordinate { coordinate.latitude(), coordinate.longitude() }; + } } QMapbox::CoordinatesCollections geometry { { coordinates } }; |