diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-06-06 13:41:56 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-07-17 15:51:28 +0000 |
commit | 73bf828559ab343a180a67db5d632bbd702a921e (patch) | |
tree | 6c376571ffdb775b7c79a9db8d894f07d1a42b84 /src/location/maps | |
parent | 4d56870212940fae747390ce4d21555164300719 (diff) | |
download | qtlocation-73bf828559ab343a180a67db5d632bbd702a921e.tar.gz |
Move anchorCoordinateToPoint into QGeoProjection
anchorCoordinateToPoint functionality actually
belongs to QGeoProjection.
Moving it there so that it can be used in other
parts of the module.
Change-Id: Id135a7a4bbe14d9c83ef160682a317e3426b15ac
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/maps')
-rw-r--r-- | src/location/maps/qgeoprojection.cpp | 16 | ||||
-rw-r--r-- | src/location/maps/qgeoprojection_p.h | 7 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/location/maps/qgeoprojection.cpp b/src/location/maps/qgeoprojection.cpp index 783193ed..7fefba27 100644 --- a/src/location/maps/qgeoprojection.cpp +++ b/src/location/maps/qgeoprojection.cpp @@ -73,6 +73,17 @@ QGeoProjection::~QGeoProjection() } +QGeoCoordinate QGeoProjection::anchorCoordinateToPoint(const QGeoCoordinate &coordinate, const QPointF &anchorPoint) const +{ + // Approach: find the displacement in (wrapped) mercator space, and apply that to the center + QDoubleVector2D centerProj = geoToWrappedMapProjection(cameraData().center()); + QDoubleVector2D coordProj = geoToWrappedMapProjection(coordinate); + + QDoubleVector2D anchorProj = itemPositionToWrappedMapProjection(QDoubleVector2D(anchorPoint)); + // Y-clamping done in mercatorToCoord + return wrappedMapProjectionToGeo(centerProj + coordProj - anchorProj); +} + /* * QGeoProjectionWebMercator implementation */ @@ -490,6 +501,11 @@ void QGeoProjectionWebMercator::updateVisibleRegion() m_visibleRegion = QClipperUtils::pathToQList(res[0]); // Intersection between two convex quadrilaterals should always be a single polygon } +QGeoCameraData QGeoProjectionWebMercator::cameraData() const +{ + return m_cameraData; +} + /* * * Line implementation diff --git a/src/location/maps/qgeoprojection_p.h b/src/location/maps/qgeoprojection_p.h index 3a0dec1d..d3be1177 100644 --- a/src/location/maps/qgeoprojection_p.h +++ b/src/location/maps/qgeoprojection_p.h @@ -91,6 +91,12 @@ public: virtual QDoubleVector2D geoToWrappedMapProjection(const QGeoCoordinate &coordinate) const = 0; virtual QGeoCoordinate wrappedMapProjectionToGeo(const QDoubleVector2D &wrappedProjection) const = 0; virtual QMatrix4x4 quickItemTransformation(const QGeoCoordinate &coordinate, const QPointF &anchorPoint, qreal zoomLevel) const = 0; + + // Returns the new map center after anchoring coordinate to anchorPoint on the screen + QGeoCoordinate anchorCoordinateToPoint(const QGeoCoordinate &coordinate, const QPointF &anchorPoint) const; + +private: + virtual QGeoCameraData cameraData() const = 0; }; class Q_LOCATION_PRIVATE_EXPORT QGeoProjectionWebMercator : public QGeoProjection @@ -132,6 +138,7 @@ public: private: void setupCamera(); void updateVisibleRegion(); + QGeoCameraData cameraData() const Q_DECL_OVERRIDE; public: struct Line2D |