summaryrefslogtreecommitdiffstats
path: root/src/location/maps/qgeotiledmapscene.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2016-12-02 18:22:12 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-01-16 16:18:27 +0000
commit762dc9dd2b47f908c3739173aa1e108dd7386717 (patch)
tree201747076f1ee6deda535a6e58cafc4edaa37cbe /src/location/maps/qgeotiledmapscene.cpp
parent45b1f2c23cf0e782c0b99f38e4d01a88da765753 (diff)
Move the coordinate <-> item position conversion to QGeoProjection
This patch simplifies the QGeoMap API removing all the API necessary to convert to and from screen. This is now demanded to a specific QGeoProjection class, that will be independent of the map, except for using the same Geo projection (currently only WebMercator, or EPSG:3857, although we use a sphere instead of an ellipsoid, i believe) The benefits are - This relieves subclasses of QGeoMap from implementing a GeoProjection API, especially since QtLocation currently supports only WebMercator, and reimplementations would have to anyway produce the same results as the inbuilt one. - This avoids the several indirection steps previously necessary to perform a map projection (qgeotiledmap -> private->mapscene-> private). Since these operation are quite frequent one per map item coordinate at every redraw, shortening the indirection chain is beneficial - It simplifies the highly complex QGeoTiledMapScene, separating all the logic that is not needed to draw the scene, but only to perform geo coordinate <-> screen coordinate conversion Change-Id: I9e3ca5280166f2d6430a32deb44c030d02d9d4e1 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/maps/qgeotiledmapscene.cpp')
-rw-r--r--src/location/maps/qgeotiledmapscene.cpp148
1 files changed, 0 insertions, 148 deletions
diff --git a/src/location/maps/qgeotiledmapscene.cpp b/src/location/maps/qgeotiledmapscene.cpp
index 5f9a52b0..404dcd19 100644
--- a/src/location/maps/qgeotiledmapscene.cpp
+++ b/src/location/maps/qgeotiledmapscene.cpp
@@ -75,7 +75,6 @@ public:
// the number of tiles in each direction for the whole map (earth) at the current zoom level.
// it is 1<<zoomLevel
int m_sideLength;
- double m_mapEdgeSize;
QHash<QGeoTileSpec, QSharedPointer<QGeoTileTexture> > m_textures;
@@ -86,14 +85,6 @@ public:
int m_maxTileY;
int m_tileXWrapsBelow; // the wrap point as a tile index
- // mercator to camera transform for coordinates (not tiles!)
- double m_cameraCenterXMercator;
- double m_cameraCenterYMercator;
- double m_cameraWidthMercator;
- double m_cameraHeightMercator;
- double m_1_cameraWidthMercator;
- double m_1_cameraHeightMercator;
-
// cameraToScreen transform
double m_screenWidth; // in pixels
double m_screenHeight; // in pixels
@@ -151,7 +142,6 @@ void QGeoTiledMapScene::setCameraData(const QGeoCameraData &cameraData)
float delta = cameraData.zoomLevel() - d->m_intZoomLevel;
d->m_linearScaling = qAbs(delta) > 0.05;
d->m_sideLength = 1 << d->m_intZoomLevel;
- d->m_mapEdgeSize = std::pow(2.0, cameraData.zoomLevel()) * d->m_tileSize;
}
void QGeoTiledMapScene::setVisibleTiles(const QSet<QGeoTileSpec> &tiles)
@@ -172,60 +162,6 @@ void QGeoTiledMapScene::addTile(const QGeoTileSpec &spec, QSharedPointer<QGeoTil
d->addTile(spec, texture);
}
-double QGeoTiledMapScene::mapEdgeSize() const
-{
- Q_D(const QGeoTiledMapScene);
- return d->m_mapEdgeSize;
-}
-
-QDoubleVector2D QGeoTiledMapScene::itemPositionToMercator(const QDoubleVector2D &pos) const
-{
- Q_D(const QGeoTiledMapScene);
- return d->itemPositionToMercator(pos);
-}
-
-QDoubleVector2D QGeoTiledMapScene::mercatorToItemPosition(const QDoubleVector2D &mercator) const
-{
- Q_D(const QGeoTiledMapScene);
- return d->mercatorToItemPosition(mercator);
-}
-
-QDoubleVector2D QGeoTiledMapScene::geoToMapProjection(const QGeoCoordinate &coordinate) const
-{
- Q_D(const QGeoTiledMapScene);
- return d->geoToMapProjection(coordinate);
-}
-
-QGeoCoordinate QGeoTiledMapScene::mapProjectionToGeo(const QDoubleVector2D &projection) const
-{
- Q_D(const QGeoTiledMapScene);
- return d->mapProjectionToGeo(projection);
-}
-
-QDoubleVector2D QGeoTiledMapScene::wrapMapProjection(const QDoubleVector2D &projection) const
-{
- Q_D(const QGeoTiledMapScene);
- return d->wrapMapProjection(projection);
-}
-
-QDoubleVector2D QGeoTiledMapScene::unwrapMapProjection(const QDoubleVector2D &wrappedProjection) const
-{
- Q_D(const QGeoTiledMapScene);
- return d->unwrapMapProjection(wrappedProjection);
-}
-
-QDoubleVector2D QGeoTiledMapScene::wrappedMapProjectionToItemPosition(const QDoubleVector2D &wrappedProjection) const
-{
- Q_D(const QGeoTiledMapScene);
- return d->wrappedMapProjectionToItemPosition(wrappedProjection);
-}
-
-QDoubleVector2D QGeoTiledMapScene::itemPositionToWrappedMapProjection(const QDoubleVector2D &itemPosition) const
-{
- Q_D(const QGeoTiledMapScene);
- return d->itemPositionToWrappedMapProjection(itemPosition);
-}
-
QSet<QGeoTileSpec> QGeoTiledMapScene::texturedTiles()
{
Q_D(QGeoTiledMapScene);
@@ -254,10 +190,6 @@ QGeoTiledMapScenePrivate::QGeoTiledMapScenePrivate()
m_maxTileX(-1),
m_maxTileY(-1),
m_tileXWrapsBelow(0),
- m_cameraCenterXMercator(0),
- m_cameraCenterYMercator(0),
- m_cameraWidthMercator(0),
- m_cameraHeightMercator(0),
m_screenWidth(0.0),
m_screenHeight(0.0),
m_linearScaling(false),
@@ -269,79 +201,6 @@ QGeoTiledMapScenePrivate::~QGeoTiledMapScenePrivate()
{
}
-// Old screenToMercator logic
-QDoubleVector2D QGeoTiledMapScenePrivate::itemPositionToMercator(const QDoubleVector2D &pos) const
-{
- return unwrapMapProjection(itemPositionToWrappedMapProjection(pos));
-}
-
-// Old mercatorToScreen logic
-QDoubleVector2D QGeoTiledMapScenePrivate::mercatorToItemPosition(const QDoubleVector2D &mercator) const
-{
- return wrappedMapProjectionToItemPosition(wrapMapProjection(mercator));
-}
-
-QDoubleVector2D QGeoTiledMapScenePrivate::geoToMapProjection(const QGeoCoordinate &coordinate) const
-{
- return QWebMercator::coordToMercator(coordinate);
-}
-
-QGeoCoordinate QGeoTiledMapScenePrivate::mapProjectionToGeo(const QDoubleVector2D &projection) const
-{
- return QWebMercator::mercatorToCoord(projection);
-}
-
-//wraps around center
-QDoubleVector2D QGeoTiledMapScenePrivate::wrapMapProjection(const QDoubleVector2D &projection) const
-{
- double x = projection.x();
- if (m_cameraCenterXMercator < 0.5) {
- if (x - m_cameraCenterXMercator > 0.5 )
- x -= 1.0;
- } else if (m_cameraCenterXMercator > 0.5) {
- if (x - m_cameraCenterXMercator < -0.5 )
- x += 1.0;
- }
-
- return QDoubleVector2D(x, projection.y());
-}
-
-QDoubleVector2D QGeoTiledMapScenePrivate::unwrapMapProjection(const QDoubleVector2D &wrappedProjection) const
-{
- double x = wrappedProjection.x();
- if (x > 1.0)
- return QDoubleVector2D(x - 1.0, wrappedProjection.y());
- if (x <= 0.0)
- return QDoubleVector2D(x + 1.0, wrappedProjection.y());
- return wrappedProjection;
-}
-
-QDoubleVector2D QGeoTiledMapScenePrivate::wrappedMapProjectionToItemPosition(const QDoubleVector2D &wrappedProjection) const
-{
- // TODO: Support tilt/bearing through a projection matrix.
- double x = ((wrappedProjection.x() - m_cameraCenterXMercator) * m_1_cameraWidthMercator + 0.5) * m_screenSize.width();
- double y = ((wrappedProjection.y() - m_cameraCenterYMercator) * m_1_cameraHeightMercator + 0.5) * m_screenSize.height();
- return QDoubleVector2D(x, y);
-}
-
-QDoubleVector2D QGeoTiledMapScenePrivate::itemPositionToWrappedMapProjection(const QDoubleVector2D &itemPosition) const
-{
- // TODO: Support tilt/bearing through an inverse projection matrix.
- double x = itemPosition.x();
- x /= m_screenSize.width();
- x -= 0.5;
- x *= m_cameraWidthMercator;
- x += m_cameraCenterXMercator;
-
- double y = itemPosition.y();
- y /= m_screenSize.height();
- y -= 0.5;
- y *= m_cameraHeightMercator;
- y += m_cameraCenterYMercator;
-
- return QDoubleVector2D(x, y);
-}
-
bool QGeoTiledMapScenePrivate::buildGeometry(const QGeoTileSpec &spec, QSGImageNode *imageNode)
{
int x = spec.x();
@@ -508,19 +367,12 @@ void QGeoTiledMapScenePrivate::setupCamera()
// the tiles or repeated tiles)
double altitude = f / (2.0 * z) ;
- m_cameraWidthMercator = m_screenSize.width() / m_mapEdgeSize;
- m_cameraHeightMercator = m_screenSize.height() / m_mapEdgeSize;
- m_1_cameraWidthMercator = 1.0 / m_cameraWidthMercator;
- m_1_cameraHeightMercator = 1.0 / m_cameraHeightMercator;
-
// calculate center
double edge = m_scaleFactor * m_tileSize;
// first calculate the camera center in map space in the range of 0 <-> sideLength (2^z)
QDoubleVector2D camCenterMercator = QWebMercator::coordToMercator(m_cameraData.center());
QDoubleVector3D center = m_sideLength * camCenterMercator;
- m_cameraCenterXMercator = camCenterMercator.x();
- m_cameraCenterYMercator = camCenterMercator.y();
// wrap the center if necessary (due to dateline crossing)
if (center.x() < m_tileXWrapsBelow)