summaryrefslogtreecommitdiff
path: root/src/location/maps/qgeotiledmap.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2016-12-02 18:18:23 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-01-16 16:18:23 +0000
commit45b1f2c23cf0e782c0b99f38e4d01a88da765753 (patch)
tree1bfe5d5706db94722b3956ac17b65897b2370d30 /src/location/maps/qgeotiledmap.cpp
parent5504a4c00ec01fdbc95a862c9bc63a680095daee (diff)
downloadqtlocation-45b1f2c23cf0e782c0b99f38e4d01a88da765753.tar.gz
Make zoomLevel refer to a default 256^2 tile size
Currently the zoomLevel is the power of 2 reflecting how many tiles are in a map edge. This means that two plugins with two different tileSize will show a map of different size at the same zoomLevel. With this patch the zoomLevel is "normalized" upon a tileSize of 256, regardless of the tile size in use. In this way, the new 256 based zoom level can be a consistent parameter also for plugins that are not tile based. CameraCapabilities therefore now offers two new methods, m[in,ax]imumZoomLevelAt256, that return the respective value for the normalized 256^2 tilesize. It also gets a setTileSize, which is currently not used as all our plugins use a tile size of 256 (which is the camera capabilities default tilesize value). Change-Id: Ib12092fd14faf7fc85f8be5fb799dbd5496b760b Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/maps/qgeotiledmap.cpp')
-rw-r--r--src/location/maps/qgeotiledmap.cpp33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/location/maps/qgeotiledmap.cpp b/src/location/maps/qgeotiledmap.cpp
index f2c1d4d3..0916c7b7 100644
--- a/src/location/maps/qgeotiledmap.cpp
+++ b/src/location/maps/qgeotiledmap.cpp
@@ -49,6 +49,18 @@
QT_BEGIN_NAMESPACE
#define PREFETCH_FRUSTUM_SCALE 2.0
+static const double invLog2 = 1.0 / std::log(2.0);
+
+static double zoomLevelFrom256(double zoomLevelFor256, double tileSize)
+{
+ return std::log( std::pow(2.0, zoomLevelFor256) * 256.0 / tileSize ) * invLog2;
+}
+
+static double zoomLevelTo256(double zoomLevelForTileSize, double tileSize)
+{
+ return std::log( std::pow(2.0, zoomLevelForTileSize) * tileSize / 256.0 ) * invLog2;
+}
+
QGeoTiledMap::QGeoTiledMap(QGeoTiledMappingManagerEngine *engine, QObject *parent)
: QGeoMap(*new QGeoTiledMapPrivate(engine), parent)
{
@@ -150,13 +162,16 @@ void QGeoTiledMap::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles)
}
// This method returns the minimum zoom level that this specific qgeomap type allows
-// at a given canvas size (width,height) and for a given tile size (usually 256).
+// at a given canvas size (width,height) and for the default tile size of 256^2
double QGeoTiledMap::minimumZoomAtViewportSize(int width, int height) const
{
Q_D(const QGeoTiledMap);
+ double tileSize = d->m_visibleTiles->tileSize();
double maxSize = qMax(width,height);
- double numTiles = maxSize / d->m_visibleTiles->tileSize();
- return std::log(numTiles) / std::log(2.0);
+ double numTiles = maxSize / tileSize;
+ if (tileSize == 256.0)
+ return std::log(numTiles) * invLog2;
+ return zoomLevelTo256(std::log(numTiles) * invLog2, tileSize);
}
// This method recalculates the "no-trespassing" limits for the map center.
@@ -275,10 +290,18 @@ void QGeoTiledMapPrivate::changeCameraData(const QGeoCameraData &cameraData)
{
Q_Q(QGeoTiledMap);
+ QGeoCameraData cam = cameraData;
+
+ // The incoming zoom level is intended for a tileSize of 256.
+ // Adapt it to the current tileSize
+ double zoomLevel = cameraData.zoomLevel();
+ if (m_visibleTiles->tileSize() != 256)
+ zoomLevel = zoomLevelFrom256(zoomLevel, m_visibleTiles->tileSize());
+ cam.setZoomLevel(zoomLevel);
+
// For zoomlevel, "snap" 0.01 either side of a whole number.
// This is so that when we turn off bilinear scaling, we're
// snapped to the exact pixel size of the tiles
- QGeoCameraData cam = cameraData;
int izl = static_cast<int>(std::floor(cam.zoomLevel()));
float delta = cam.zoomLevel() - izl;
@@ -286,6 +309,8 @@ void QGeoTiledMapPrivate::changeCameraData(const QGeoCameraData &cameraData)
izl++;
delta -= 1.0;
}
+
+ // TODO: Don't do this if there's tilt or bearing.
if (qAbs(delta) < 0.01) {
cam.setZoomLevel(izl);
}