summaryrefslogtreecommitdiff
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
parentf586ea00feb414fb0776aa2bc6fbbb356ac61c32 (diff)
downloadqtlocation-a33f9131a3f5b07831ea9565cb0dc22e078f9475.tar.gz
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>
-rw-r--r--src/imports/location/qdeclarativecirclemapitem.cpp2
-rw-r--r--src/imports/location/qdeclarativepolygonmapitem.cpp35
-rw-r--r--src/imports/location/qdeclarativepolylinemapitem.cpp19
3 files changed, 31 insertions, 25 deletions
diff --git a/src/imports/location/qdeclarativecirclemapitem.cpp b/src/imports/location/qdeclarativecirclemapitem.cpp
index 7961305f..5e139bd5 100644
--- a/src/imports/location/qdeclarativecirclemapitem.cpp
+++ b/src/imports/location/qdeclarativecirclemapitem.cpp
@@ -506,7 +506,7 @@ void QDeclarativeCircleMapItem::updatePolish()
setHeight(geometry_.screenBoundingBox().height());
}
- setPositionOnMap(circlePath_.at(0), geometry_.firstPointOffset());
+ setPositionOnMap(geoLeftBound_, geometry_.firstPointOffset());
}
/*!
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) {
diff --git a/src/imports/location/qdeclarativepolylinemapitem.cpp b/src/imports/location/qdeclarativepolylinemapitem.cpp
index a31fcbad..486b2c6f 100644
--- a/src/imports/location/qdeclarativepolylinemapitem.cpp
+++ b/src/imports/location/qdeclarativepolylinemapitem.cpp
@@ -200,12 +200,14 @@ void QGeoMapPolylineGeometry::updateSourcePoints(const QGeoMap &map,
srcPointTypes_.clear();
srcPointTypes_.reserve(path.size());
- QDoubleVector2D origin, lastAddedPoint;
-
+ QDoubleVector2D lastAddedPoint;
const double mapWidthHalf = map.viewportWidth()/2.0;
+ QDoubleVector2D origin = map.geoProjection().coordinateToItemPosition(geoLeftBound_, false);
+
+ srcOrigin_ = geoLeftBound_;
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);
@@ -236,9 +238,8 @@ void QGeoMapPolylineGeometry::updateSourcePoints(const QGeoMap &map,
if (!foundValid) {
foundValid = true;
- srcOrigin_ = coord; // TODO: Make this consistent with the left bound
- origin = point;
- point = QDoubleVector2D(0,0);
+
+ point = point - origin; // (0,0) if point == geoLeftBound_
minX = point.x();
maxX = minX;
@@ -827,8 +828,8 @@ void QDeclarativePolylineMapItem::geometryChanged(const QRectF &newGeometry, con
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) {
@@ -903,7 +904,7 @@ void QDeclarativePolylineMapItem::updatePolish()
setWidth(geometry_.sourceBoundingBox().width());
setHeight(geometry_.sourceBoundingBox().height());
- setPositionOnMap(path_.at(0), -1 * geometry_.sourceBoundingBox().topLeft());
+ setPositionOnMap(geoLeftBound_, -1 * geometry_.sourceBoundingBox().topLeft());
}
/*!