diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-12-02 18:18:23 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-01-16 16:18:23 +0000 |
commit | 45b1f2c23cf0e782c0b99f38e4d01a88da765753 (patch) | |
tree | 1bfe5d5706db94722b3956ac17b65897b2370d30 /src/location/maps/qgeocameracapabilities.cpp | |
parent | 5504a4c00ec01fdbc95a862c9bc63a680095daee (diff) | |
download | qtlocation-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/qgeocameracapabilities.cpp')
-rw-r--r-- | src/location/maps/qgeocameracapabilities.cpp | 42 |
1 files changed, 40 insertions, 2 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. |