summaryrefslogtreecommitdiff
path: root/src/plugins/geoservices/mapbox
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 /src/plugins/geoservices/mapbox
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>
Diffstat (limited to 'src/plugins/geoservices/mapbox')
-rw-r--r--src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp28
1 files changed, 18 insertions, 10 deletions
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"))) {