summaryrefslogtreecommitdiff
path: root/src/location/maps
diff options
context:
space:
mode:
Diffstat (limited to 'src/location/maps')
-rw-r--r--src/location/maps/qgeoprojection.cpp16
-rw-r--r--src/location/maps/qgeoprojection_p.h7
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