summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2016-10-19 17:14:22 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2016-11-22 09:29:39 +0000
commit3a6fb42cb2bb72f51f9fc05c5f6651a659cb9c8b (patch)
tree386cbc97816da5cee9c6ddd5b8b1330359a811cd
parent95f8804ecaed79792a57b1fe3580266bfbbf7590 (diff)
downloadqtlocation-3a6fb42cb2bb72f51f9fc05c5f6651a659cb9c8b.tar.gz
Add support for unitary tile cost in QGeoFileTileCache
This patch adds support for unitary pricing of tiles in the disk, memory and texture caches. This is done through a new enum in QAbstractGeoTileCache, "CostStrategy" having two values, Unitary (new one) and ByteSize (the old way). Using Unitary instead of ByteSize gives, as advantages: - the ability to comply with the TOS of certain providers, who allow to cache a fixed number of tiles, and not of bytes. - even performance with different types of tiles, like lo vs hi res, indexed vs satellite (which usually compresses much less). This patch sets the Unitary mode to be the default for the mapbox plugin since Mapbox is one of the providers whose TOS limit the amount of cacheable tiles. Therefore, the patch also modifies the mapbox plugin ".mapping.cache" parameters to reflect the new behavior. Since these parameters have been introduced with 5.8 (which is unreleased), the change doesn't need to be backward compatible. Change-Id: I76edd43900242885f24eb9f28e8c833538647edc Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/location/doc/src/plugins/mapbox.qdoc30
-rw-r--r--src/location/maps/qabstractgeotilecache_p.h6
-rw-r--r--src/location/maps/qgeofiletilecache.cpp43
-rw-r--r--src/location/maps/qgeofiletilecache_p.h4
-rw-r--r--src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp28
5 files changed, 84 insertions, 27 deletions
diff --git a/src/location/doc/src/plugins/mapbox.qdoc b/src/location/doc/src/plugins/mapbox.qdoc
index bc67822a..617be5cf 100644
--- a/src/location/doc/src/plugins/mapbox.qdoc
+++ b/src/location/doc/src/plugins/mapbox.qdoc
@@ -92,18 +92,34 @@ The following table lists optional parameters that can be passed to the Mapbox p
The default place for the cache is \c{QtLocation/mapbox} directory in \l {QStandardPaths::writableLocation()} {QStandardPaths::writableLocation}(\l{QStandardPaths::GenericCacheLocation}).
On systems that have no concept of a shared cache, the application-specific \l{QStandardPaths::CacheLocation} is used instead.
\row
+ \li mapbox.mapping.cache.cost_strategy
+ \li The cost strategy to use to cache map tiles.
+ Valid values are \b bytesize and \b unitary.
+ Using \b bytesize, the size parameters (\b mapbox.mapping.cache.disk.size,
+ \b mapbox.mapping.cache.memory.size and \b mapbox.mapping.cache.texture.size) will
+ be interpreted as bytes.
+ Using \b unitary, they will be interpreted as number of tiles.
+ The default value is \b unitary.
+\row
\li mapbox.mapping.cache.disk.size
- \li Map tile disk cache size in bytes. Default size of the cache is 300MB.
- Note that this is the maximum amount of data that the Mapbox free plan allows to cache.
+ \li Disk cache size for map tiles.
+ The default size of this cache is 6000 if \b unitary is used as cost strategy,
+ or 50 MiB, if \b bytesize is used as cost strategy.
+ Note that 6000 is the maximum amount of tiles that the Mapbox free plan allows to cache.
Make sure to comply with Mapbox Terms of Service before increasing this value.
\row
\li mapbox.mapping.cache.memory.size
- \li Map tile memory cache size in bytes. Default size of the cache is 3MB.
+ \li Memory cache size for map tiles.
+ The Default size of this cache is 100 if \b unitary is used as cost strategy, or
+ 3 MiB, if \b bytesize is used as cost strategy.
\row
\li mapbox.mapping.cache.texture.size
- \li Map tile texture cache size in bytes. Default size of the cache is 6MB.
- Note that the texture cache has a hard minimum size which depends on the size of the map viewport
- (it must contain enough data to display the tiles currently visible on the display).
- This value is the amount of cache to be used in addition to the bare minimum.
+ \li Texture cache size for map tiles.
+ The Default size of this cache is 30 if \b unitary is used as cost strategy, or
+ 6 MiB, if \b bytesize is used as cost strategy.
+ Note that the texture cache has a hard minimum size which depends on the size of the map
+ viewport (it must contain enough data to display the tiles currently visible on the
+ display).
+ This value is the amount of tiles to be cached in addition to the bare minimum.
\endtable
*/
diff --git a/src/location/maps/qabstractgeotilecache_p.h b/src/location/maps/qabstractgeotilecache_p.h
index 8cd303ee..6660d13a 100644
--- a/src/location/maps/qabstractgeotilecache_p.h
+++ b/src/location/maps/qabstractgeotilecache_p.h
@@ -87,6 +87,10 @@ class Q_LOCATION_EXPORT QAbstractGeoTileCache : public QObject
{
Q_OBJECT
public:
+ enum CostStrategy {
+ Unitary,
+ ByteSize
+ };
virtual ~QAbstractGeoTileCache();
virtual void setMaxDiskUsage(int diskUsage);
@@ -103,6 +107,8 @@ public:
virtual int minTextureUsage() const = 0;
virtual int textureUsage() const = 0;
virtual void clearAll() = 0;
+ virtual void setCostStrategy(CostStrategy costStrategy) = 0;
+ virtual CostStrategy costStrategy() = 0;
virtual QSharedPointer<QGeoTileTexture> get(const QGeoTileSpec &spec) = 0;
diff --git a/src/location/maps/qgeofiletilecache.cpp b/src/location/maps/qgeofiletilecache.cpp
index 95bce268..fee31dbd 100644
--- a/src/location/maps/qgeofiletilecache.cpp
+++ b/src/location/maps/qgeofiletilecache.cpp
@@ -86,7 +86,7 @@ QGeoCachedTileDisk::~QGeoCachedTileDisk()
}
QGeoFileTileCache::QGeoFileTileCache(const QString &directory, QObject *parent)
- : QAbstractGeoTileCache(parent), directory_(directory), minTextureUsage_(0), extraTextureUsage_(0)
+ : QAbstractGeoTileCache(parent), directory_(directory), minTextureUsage_(0), extraTextureUsage_(0), costStrategy_(ByteSize)
{
}
@@ -119,9 +119,15 @@ void QGeoFileTileCache::init()
QDir::root().mkpath(directory_);
// default values
- setMaxDiskUsage(50 * 1024 * 1024);
- setMaxMemoryUsage(3 * 1024 * 1024);
- setExtraTextureUsage(6 * 1024 * 1024);
+ if (costStrategy_ == ByteSize) {
+ setMaxDiskUsage(50 * 1024 * 1024);
+ setMaxMemoryUsage(3 * 1024 * 1024);
+ setExtraTextureUsage(6 * 1024 * 1024);
+ } else {
+ setMaxDiskUsage(1000);
+ setMaxMemoryUsage(100);
+ setExtraTextureUsage(30); // byte size of texture is >> compressed image, hence unitary cost should be lower
+ }
loadTiles();
}
@@ -312,6 +318,16 @@ void QGeoFileTileCache::clearMapId(const int mapId)
}
}
+void QGeoFileTileCache::setCostStrategy(QAbstractGeoTileCache::CostStrategy costStrategy)
+{
+ costStrategy_ = costStrategy;
+}
+
+QAbstractGeoTileCache::CostStrategy QGeoFileTileCache::costStrategy()
+{
+ return costStrategy_;
+}
+
QSharedPointer<QGeoTileTexture> QGeoFileTileCache::get(const QGeoTileSpec &spec)
{
QSharedPointer<QGeoTileTexture> tt = getFromMemory(spec);
@@ -363,9 +379,12 @@ QSharedPointer<QGeoCachedTileDisk> QGeoFileTileCache::addToDiskCache(const QGeoT
td->filename = filename;
td->cache = this;
- QFileInfo fi(filename);
- int diskCost = fi.size();
- diskCache_.insert(spec, td, diskCost);
+ int cost = 1;
+ if (costStrategy_ == ByteSize) {
+ QFileInfo fi(filename);
+ cost = fi.size();
+ }
+ diskCache_.insert(spec, td, cost);
return td;
}
@@ -377,7 +396,9 @@ QSharedPointer<QGeoCachedTileMemory> QGeoFileTileCache::addToMemoryCache(const Q
tm->bytes = bytes;
tm->format = format;
- int cost = bytes.size();
+ int cost = 1;
+ if (costStrategy_ == ByteSize)
+ cost = bytes.size();
memoryCache_.insert(spec, tm, cost);
return tm;
@@ -389,8 +410,10 @@ QSharedPointer<QGeoTileTexture> QGeoFileTileCache::addToTextureCache(const QGeoT
tt->spec = spec;
tt->image = image;
- int textureCost = image.width() * image.height() * image.depth() / 8;
- textureCache_.insert(spec, tt, textureCost);
+ int cost = 1;
+ if (costStrategy_ == ByteSize)
+ cost = image.width() * image.height() * image.depth() / 8;
+ textureCache_.insert(spec, tt, cost);
return tt;
}
diff --git a/src/location/maps/qgeofiletilecache_p.h b/src/location/maps/qgeofiletilecache_p.h
index e850a13b..96fcf1ee 100644
--- a/src/location/maps/qgeofiletilecache_p.h
+++ b/src/location/maps/qgeofiletilecache_p.h
@@ -118,6 +118,9 @@ public:
int textureUsage() const Q_DECL_OVERRIDE;
void clearAll() Q_DECL_OVERRIDE;
void clearMapId(const int mapId);
+ void setCostStrategy(CostStrategy costStrategy) Q_DECL_OVERRIDE;
+ CostStrategy costStrategy() Q_DECL_OVERRIDE;
+
QSharedPointer<QGeoTileTexture> get(const QGeoTileSpec &spec) Q_DECL_OVERRIDE;
@@ -154,6 +157,7 @@ protected:
int minTextureUsage_;
int extraTextureUsage_;
+ CostStrategy costStrategy_;
};
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp
index 3dccca4b..1fbda8e0 100644
--- a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp
+++ b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp
@@ -149,24 +149,32 @@ QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const Q
m_cacheDirectory = QAbstractGeoTileCache::baseLocationCacheDirectory() + QLatin1String("mapbox");
}
- // The Mapbox free plan allows for 6000 tiles to be stored for offline uses
- // As of 2016.06.15, according to https://www.mapbox.com/help/mobile-offline/ ,
- // this translates into 45-315 MiB, depending on the map and the area.
- // Setting a default limit of 300MiB, which can be overridden via parameters, if
- // the plan allows for more data to be stored offline.
- // NOTE:
- // It is illegal to violate Mapbox Terms of Service, setting a limit that exceeds
- // what the plan the token belongs to allows.
-
QGeoFileTileCache *tileCache = new QGeoFileTileCacheMapbox(mapTypes, scaleFactor, m_cacheDirectory);
+ // The Mapbox free plan allows for 6000 tiles to be stored for offline uses,
+ // As of 2016.06.15, according to https://www.mapbox.com/help/mobile-offline/ .
+ // Thus defaulting to Unitary strategy, and setting 6000 tiles as default cache disk size
+ if (parameters.contains(QStringLiteral("mapbox.mapping.cache.cost_strategy"))) {
+ QString cacheStrategy = parameters.value(QStringLiteral("mapbox.mapping.cache.cost_strategy")).toString().toLower();
+ if (cacheStrategy == QLatin1String("bytesize"))
+ tileCache->setCostStrategy(QGeoFileTileCache::ByteSize);
+ else
+ tileCache->setCostStrategy(QGeoFileTileCache::Unitary);
+ } else {
+ // Default to unitary
+ tileCache->setCostStrategy(QGeoFileTileCache::Unitary);
+ }
+
+
+
if (parameters.contains(QStringLiteral("mapbox.mapping.cache.disk.size"))) {
bool ok = false;
int cacheSize = parameters.value(QStringLiteral("mapbox.mapping.cache.disk.size")).toString().toInt(&ok);
if (ok)
tileCache->setMaxDiskUsage(cacheSize);
} else {
- tileCache->setMaxDiskUsage(300 * 1024 * 1024);
+ if (tileCache->costStrategy() == QGeoFileTileCache::Unitary)
+ tileCache->setMaxDiskUsage(6000); // The maximum allowed with the free tier
}
if (parameters.contains(QStringLiteral("mapbox.mapping.cache.memory.size"))) {