summaryrefslogtreecommitdiff
path: root/src/location/maps
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
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')
-rw-r--r--src/location/maps/qgeocameracapabilities.cpp42
-rw-r--r--src/location/maps/qgeocameracapabilities_p.h5
-rw-r--r--src/location/maps/qgeotiledmap.cpp33
3 files changed, 74 insertions, 6 deletions
diff --git a/src/location/maps/qgeocameracapabilities.cpp b/src/location/maps/qgeocameracapabilities.cpp
index 7b4a014a..97ff5790 100644
--- a/src/location/maps/qgeocameracapabilities.cpp
+++ b/src/location/maps/qgeocameracapabilities.cpp
@@ -37,6 +37,14 @@
#include "qgeocameracapabilities_p.h"
#include <QSharedData>
+#include <cmath>
+
+static const double invLog2 = 1.0 / std::log(2.0);
+
+static double zoomLevelTo256(double zoomLevelForTileSize, double tileSize)
+{
+ return std::log( std::pow(2.0, zoomLevelForTileSize) * tileSize / 256.0 ) * invLog2;
+}
QT_BEGIN_NAMESPACE
@@ -60,6 +68,7 @@ public:
double maxZoom_;
double minTilt_;
double maxTilt_;
+ int tileSize_;
};
QGeoCameraCapabilitiesPrivate::QGeoCameraCapabilitiesPrivate()
@@ -70,7 +79,8 @@ QGeoCameraCapabilitiesPrivate::QGeoCameraCapabilitiesPrivate()
minZoom_(0.0),
maxZoom_(0.0),
minTilt_(0.0),
- maxTilt_(0.0) {}
+ maxTilt_(0.0),
+ tileSize_(256) {}
QGeoCameraCapabilitiesPrivate::QGeoCameraCapabilitiesPrivate(const QGeoCameraCapabilitiesPrivate &other)
@@ -82,7 +92,8 @@ QGeoCameraCapabilitiesPrivate::QGeoCameraCapabilitiesPrivate(const QGeoCameraCap
minZoom_(other.minZoom_),
maxZoom_(other.maxZoom_),
minTilt_(other.minTilt_),
- maxTilt_(other.maxTilt_) {}
+ maxTilt_(other.maxTilt_),
+ tileSize_(other.tileSize_) {}
QGeoCameraCapabilitiesPrivate::~QGeoCameraCapabilitiesPrivate() {}
@@ -99,6 +110,7 @@ QGeoCameraCapabilitiesPrivate &QGeoCameraCapabilitiesPrivate::operator = (const
maxZoom_ = other.maxZoom_;
minTilt_ = other.minTilt_;
maxTilt_ = other.maxTilt_;
+ tileSize_ = other.tileSize_;
return *this;
}
@@ -149,6 +161,18 @@ QGeoCameraCapabilities &QGeoCameraCapabilities::operator = (const QGeoCameraCapa
return *this;
}
+void QGeoCameraCapabilities::setTileSize(int tileSize)
+{
+ if (tileSize < 1)
+ return;
+ d->tileSize_ = tileSize;
+}
+
+int QGeoCameraCapabilities::tileSize() const
+{
+ return d->tileSize_;
+}
+
/*!
Returns whether this instance of the class is considered "valid". To be
valid, the instance must have had at least one capability set (to either
@@ -183,6 +207,13 @@ double QGeoCameraCapabilities::minimumZoomLevel() const
return d->minZoom_;
}
+double QGeoCameraCapabilities::minimumZoomLevelAt256() const
+{
+ if (d->tileSize_ == 256)
+ return d->minZoom_;
+ return zoomLevelTo256(d->minZoom_, d->tileSize_);
+}
+
/*!
Sets the maximum zoom level supported by the associated plugin to \a maximumZoomLevel.
@@ -206,6 +237,13 @@ double QGeoCameraCapabilities::maximumZoomLevel() const
return d->maxZoom_;
}
+double QGeoCameraCapabilities::maximumZoomLevelAt256() const
+{
+ if (d->tileSize_ == 256)
+ return d->maxZoom_;
+ return zoomLevelTo256(d->maxZoom_, d->tileSize_);
+}
+
/*!
Sets whether the associated plugin can render a map when the camera
has an arbitrary bearing to \a supportsBearing.
diff --git a/src/location/maps/qgeocameracapabilities_p.h b/src/location/maps/qgeocameracapabilities_p.h
index 4e498b1d..7de6ece0 100644
--- a/src/location/maps/qgeocameracapabilities_p.h
+++ b/src/location/maps/qgeocameracapabilities_p.h
@@ -65,11 +65,16 @@ public:
QGeoCameraCapabilities &operator = (const QGeoCameraCapabilities &other);
+ void setTileSize(int tileSize);
+ int tileSize() const;
+
void setMinimumZoomLevel(double minimumZoomLevel);
double minimumZoomLevel() const;
+ double minimumZoomLevelAt256() const;
void setMaximumZoomLevel(double maximumZoomLevel);
double maximumZoomLevel() const;
+ double maximumZoomLevelAt256() const;
void setSupportsBearing(bool supportsBearing);
bool supportsBearing() const;
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);
}