diff options
-rw-r--r-- | src/location/maps/qgeoprojection.cpp | 26 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map_item_details.qml | 10 |
2 files changed, 24 insertions, 12 deletions
diff --git a/src/location/maps/qgeoprojection.cpp b/src/location/maps/qgeoprojection.cpp index 586dcb02..8cb7a748 100644 --- a/src/location/maps/qgeoprojection.cpp +++ b/src/location/maps/qgeoprojection.cpp @@ -185,12 +185,7 @@ QDoubleVector2D QGeoProjectionWebMercator::unwrapMapProjection(const QDoubleVect QDoubleVector2D QGeoProjectionWebMercator::wrappedMapProjectionToItemPosition(const QDoubleVector2D &wrappedProjection) const { - QDoubleVector3D pos = wrappedProjection * m_sideLength; - QDoubleVector2D res = (m_transformation * pos).toVector2D(); - res += QDoubleVector2D(1.0,1.0); - res *= 0.5; - res *= QDoubleVector2D(m_viewportWidth, m_viewportHeight); - return res; + return (m_transformation * wrappedProjection).toVector2D(); } QDoubleVector2D QGeoProjectionWebMercator::itemPositionToWrappedMapProjection(const QDoubleVector2D &itemPosition) const @@ -384,7 +379,24 @@ void QGeoProjectionWebMercator::setupCamera() QDoubleMatrix4x4 projectionMatrix; projectionMatrix.frustum(-m_halfWidth, m_halfWidth, -m_halfHeight, m_halfHeight, m_nearPlane, m_farPlane); - m_transformation = projectionMatrix * cameraMatrix; + /* + * The full transformation chain for m_transformation is: + * matScreen * matScreenFit * matShift * projectionMatrix * cameraMatrix * matZoomLevelScale + * where: + * matZoomLevelScale = scale(m_sideLength, m_sideLength, 1.0) + * matShift = translate(1.0, 1.0, 0.0) + * matScreenFit = scale(0.5, 0.5, 1.0) + * matScreen = scale(m_viewportWidth, m_viewportHeight, 1.0) + */ + + QDoubleMatrix4x4 matScreenTransformation; + matScreenTransformation.scale(0.5 * m_viewportWidth, 0.5 * m_viewportHeight, 1.0); + matScreenTransformation(0,3) = 0.5 * m_viewportWidth; + matScreenTransformation(1,3) = 0.5 * m_viewportHeight; + + m_transformation = matScreenTransformation * projectionMatrix * cameraMatrix; + m_transformation.scale(m_sideLength, m_sideLength, 1.0); + m_centerNearPlane = m_eye + m_viewNormalized; m_centerNearPlaneMercator = m_eyeMercator + m_viewNormalized * m_nearPlaneMercator; diff --git a/tests/auto/declarative_ui/tst_map_item_details.qml b/tests/auto/declarative_ui/tst_map_item_details.qml index ebaf1ea7..0c5f5c0b 100644 --- a/tests/auto/declarative_ui/tst_map_item_details.qml +++ b/tests/auto/declarative_ui/tst_map_item_details.qml @@ -439,7 +439,7 @@ Item { // move item edge onto dateline extMapRectDateline.topLeft.longitude = datelineCoordinate.longitude point = map.fromCoordinate(extMapRectDateline.topLeft) - verify(point.x == map.width / 2.0) + compare(point.x, map.width / 2.0) // drag item back onto dateline verify(LocationTestHelper.waitForPolished(map)) visualInspectionPoint(inspectionTime) @@ -463,7 +463,7 @@ Item { verify(extMapCircleDateline.center.longitude === 180) map.center = datelineCoordinate point = map.fromCoordinate(extMapCircleDateline.center) - verify(point.x == map.width / 2.0) // center of the screen + compare(point.x, map.width / 2.0) // center of the screen visualInspectionPoint() extMapCircleDateline.center.longitude = datelineCoordinateRight.longitude // -170, moving the circle to the right point = map.fromCoordinate(extMapCircleDateline.center) @@ -533,12 +533,12 @@ Item { path[0].longitude = datelineCoordinate.longitude; extMapPolygonDateline.path = path; point = map.fromCoordinate(extMapPolygonDateline.path[0]) - verify(point.x == map.width / 2.0) + compare(point.x, map.width / 2.0) path = extMapPolygonDateline.path; path[3].longitude = datelineCoordinate.longitude; extMapPolygonDateline.path = path; point = map.fromCoordinate(extMapPolygonDateline.path[3]) - verify(point.x == map.width / 2.0) + compare(point.x, map.width / 2.0) verify(LocationTestHelper.waitForPolished(map)) visualInspectionPoint(inspectionTime) mousePress(map, point.x + 5, point.y - 5) @@ -575,7 +575,7 @@ Item { path[0].longitude = datelineCoordinate.longitude; extMapPolylineDateline.path = path; point = map.fromCoordinate(extMapPolylineDateline.path[0]) - verify(point.x == map.width / 2.0) + compare(point.x, map.width / 2.0) map.removeMapItem(extMapPolylineDateline) // map route |