summaryrefslogtreecommitdiffstats
path: root/src/imports/location/qdeclarativepolygonmapitem.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2016-11-15 12:58:49 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-01-26 14:45:42 +0000
commita33f9131a3f5b07831ea9565cb0dc22e078f9475 (patch)
tree9c116ab29c06147a4822abeeb8b27e2501aae04d /src/imports/location/qdeclarativepolygonmapitem.cpp
parentf586ea00feb414fb0776aa2bc6fbbb356ac61c32 (diff)
Position map items on their geoLeftBound
Currently map items are positioned based on their "first" coordinate. This was because the leftbound was updated at every point update. Now that the geo left bound is data-driven, it is possible to use it to position elements on map. So that polylines and polygons won't wrap around based on their first coordinate (wherever it is), but on their geoLeftBound. This means that two identical polygon with the coordinate list starting at different offset will wrap around in the same way. Same for polylines. And circles won't wrap around anymore on their topmost point, but based on their leftbound too. Change-Id: I04dd04633b878f85e605af8fa84c3cd477a76e32 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/imports/location/qdeclarativepolygonmapitem.cpp')
-rw-r--r--src/imports/location/qdeclarativepolygonmapitem.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/imports/location/qdeclarativepolygonmapitem.cpp b/src/imports/location/qdeclarativepolygonmapitem.cpp
index 2268c885..19d68e5c 100644
--- a/src/imports/location/qdeclarativepolygonmapitem.cpp
+++ b/src/imports/location/qdeclarativepolygonmapitem.cpp
@@ -150,14 +150,17 @@ void QGeoMapPolygonGeometry::updateSourcePoints(const QGeoMap &map,
if (!sourceDirty_)
return;
+ bool foundValid = false;
+
// build the actual path
- QDoubleVector2D origin;
- QDoubleVector2D lastPoint;
+ QDoubleVector2D lastAddedPoint;
srcPath_ = QPainterPath();
+ srcOrigin_ = geoLeftBound_;
+ QDoubleVector2D origin = map.geoProjection().coordinateToItemPosition(geoLeftBound_, false);
double unwrapBelowX = 0;
if (preserveGeometry_ )
- unwrapBelowX = map.geoProjection().coordinateToItemPosition(geoLeftBound_, false).x();
+ unwrapBelowX = origin.x();
for (int i = 0; i < path.size(); ++i) {
const QGeoCoordinate &coord = path.at(i);
@@ -178,16 +181,18 @@ void QGeoMapPolygonGeometry::updateSourcePoints(const QGeoMap &map,
&& !qFuzzyCompare(geoLeftBound_.longitude(), coord.longitude()))
point.setX(unwrapBelowX + geoDistanceToScreenWidth(map, geoLeftBound_, coord));
- if (i == 0) {
- origin = point;
- srcOrigin_ = coord;
- srcPath_.moveTo(point.toPointF() - origin.toPointF());
- lastPoint = point;
+
+ if (!foundValid) {
+ foundValid = true;
+ point = point - origin;
+ srcPath_.moveTo(point.toPointF());
+ lastAddedPoint = point;
} else {
- const QDoubleVector2D diff = (point - lastPoint);
- if (diff.x() * diff.x() + diff.y() * diff.y() >= 3.0) {
- srcPath_.lineTo(point.toPointF() - origin.toPointF());
- lastPoint = point;
+ point -= origin;
+ if ((point - lastAddedPoint).manhattanLength() > 3 ||
+ i == path.size() - 1) {
+ srcPath_.lineTo(point.toPointF());
+ lastAddedPoint = point;
}
}
}
@@ -555,7 +560,7 @@ void QDeclarativePolygonMapItem::updatePolish()
setWidth(combined.width());
setHeight(combined.height());
- setPositionOnMap(path_.at(0), -1 * geometry_.sourceBoundingBox().topLeft());
+ setPositionOnMap(geoLeftBound_, -1 * geometry_.sourceBoundingBox().topLeft());
}
/*!
@@ -605,8 +610,8 @@ void QDeclarativePolygonMapItem::geometryChanged(const QRectF &newGeometry, cons
QDoubleVector2D newPoint = QDoubleVector2D(x(),y()) + QDoubleVector2D(geometry_.firstPointOffset());
QGeoCoordinate newCoordinate = map()->geoProjection().itemPositionToCoordinate(newPoint, false);
if (newCoordinate.isValid()) {
- double firstLongitude = path_.at(0).longitude();
- double firstLatitude = path_.at(0).latitude();
+ double firstLongitude = geoLeftBound_.longitude();
+ double firstLatitude = geoLeftBound_.latitude();
double minMaxLatitude = firstLatitude;
// prevent dragging over valid min and max latitudes
for (int i = 0; i < path_.count(); ++i) {