diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-02-24 17:15:48 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-03-02 15:09:01 +0000 |
commit | 32ffdfbb4ed93df0e4b71a1ed0831813ddd51fe4 (patch) | |
tree | 015b1a56921bac43d7b01899b2f4ad20b2611942 /src/plugins/geoservices/mapboxgl | |
parent | e463bf8f4ae1eb94b4f91cb6ebca4b198e86bccd (diff) | |
download | qtlocation-32ffdfbb4ed93df0e4b71a1ed0831813ddd51fe4.tar.gz |
Unwrap longitude in Mapbox GL when needed
This is in order to keep parity with Qt visual expectations.
Change-Id: Iea758483972e53b8f42e352401390d95dd1c1407
Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
Diffstat (limited to 'src/plugins/geoservices/mapboxgl')
-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 } }; |