From 73bf828559ab343a180a67db5d632bbd702a921e Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Tue, 6 Jun 2017 13:41:56 +0200 Subject: 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 --- src/location/declarativemaps/qquickgeomapgesturearea.cpp | 16 ++-------------- src/location/maps/qgeoprojection.cpp | 16 ++++++++++++++++ src/location/maps/qgeoprojection_p.h | 7 +++++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/location/declarativemaps/qquickgeomapgesturearea.cpp b/src/location/declarativemaps/qquickgeomapgesturearea.cpp index a40afd68..6931c774 100644 --- a/src/location/declarativemaps/qquickgeomapgesturearea.cpp +++ b/src/location/declarativemaps/qquickgeomapgesturearea.cpp @@ -84,18 +84,6 @@ static qreal distanceBetweenTouchPoints(const QPointF &p1, const QPointF &p2) return QLineF(p1, p2).length(); } -// Returns the new map center after anchoring coordinate to anchorPoint on the screen -// Approach: find the displacement in (wrapped) mercator space, and apply that to the center -static QGeoCoordinate anchorCoordinateToPoint(QGeoMap &map, const QGeoCoordinate &coordinate, const QPointF &anchorPoint) -{ - QDoubleVector2D centerProj = map.geoProjection().geoToWrappedMapProjection(map.cameraData().center()); - QDoubleVector2D coordProj = map.geoProjection().geoToWrappedMapProjection(coordinate); - - QDoubleVector2D anchorProj = map.geoProjection().itemPositionToWrappedMapProjection(QDoubleVector2D(anchorPoint)); - // Y-clamping done in mercatorToCoord - return map.geoProjection().wrappedMapProjectionToGeo(centerProj + coordProj - anchorProj); -} - static qreal angleFromPoints(const QPointF &p1, const QPointF &p2) { return QLineF(p1, p2).angle(); @@ -958,7 +946,7 @@ void QQuickGeoMapGestureArea::handleWheelEvent(QWheelEvent *event) const QPointF &postZoomPoint = m_map->geoProjection().coordinateToItemPosition(wheelGeoPos, false).toPointF(); if (preZoomPoint != postZoomPoint) // need to re-anchor the wheel geoPos to the event position - m_declarativeMap->setCenter(anchorCoordinateToPoint(*m_map, wheelGeoPos, preZoomPoint)); + m_declarativeMap->setCenter(m_map->geoProjection().anchorCoordinateToPoint(wheelGeoPos, preZoomPoint)); event->accept(); } @@ -1705,7 +1693,7 @@ bool QQuickGeoMapGestureArea::canStartPan() */ void QQuickGeoMapGestureArea::updatePan() { - QGeoCoordinate animationStartCoordinate = anchorCoordinateToPoint(*m_map, m_startCoord, m_touchPointsCentroid); + QGeoCoordinate animationStartCoordinate = m_map->geoProjection().anchorCoordinateToPoint(m_startCoord, m_touchPointsCentroid); m_declarativeMap->setCenter(animationStartCoordinate); } 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 -- cgit v1.2.1