diff options
author | Paolo Angelelli <paolo.angelelli@theqtcompany.com> | 2016-07-06 20:01:59 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@theqtcompany.com> | 2016-07-19 12:16:31 +0000 |
commit | 10b708e419c672411507feceb4c7869a5024df1e (patch) | |
tree | f08b8290bc6d9e2487930a285b58a4ffc678358c /src/plugins/geoservices/mapbox | |
parent | 208c822225fe2a7a7e214dfb04acc48de5a7d001 (diff) | |
download | qtlocation-10b708e419c672411507feceb4c7869a5024df1e.tar.gz |
Differentiate cached tiles by dpi
This patch uses separate filenames for tiles
downloaded at different resolutions/dpi.
For the HERE plugin, the dpi is appeneded
to the filename.
For the mapbox plugin, @1x or @2x is used
due to the different approach to High DPI
tiles.
Change-Id: I0dcda088dae84e98c0e73bdc24435d7e2a3f43f7
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/plugins/geoservices/mapbox')
5 files changed, 30 insertions, 14 deletions
diff --git a/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp b/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp index 4057568d..6ce41a2b 100644 --- a/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp +++ b/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp @@ -40,9 +40,10 @@ QT_BEGIN_NAMESPACE -QGeoFileTileCacheMapbox::QGeoFileTileCacheMapbox(const QList<QGeoMapType> &mapTypes, const QString &directory, QObject *parent) +QGeoFileTileCacheMapbox::QGeoFileTileCacheMapbox(const QList<QGeoMapType> &mapTypes, int scaleFactor, const QString &directory, QObject *parent) :QGeoFileTileCache(directory, parent), m_mapTypes(mapTypes) { + m_scaleFactor = qBound(1, scaleFactor, 2); for (int i=0; i < mapTypes.size(); i++) m_mapNameToId.insert(mapTypes[i].name(), i); } @@ -70,6 +71,10 @@ QString QGeoFileTileCacheMapbox::tileSpecToFilename(const QGeoTileSpec &spec, co filename += QString::number(spec.version()); } + filename += QLatin1String("-@"); + filename += QString::number(m_scaleFactor); + filename += QLatin1Char('x'); + filename += QLatin1String("."); filename += format; @@ -89,13 +94,21 @@ QGeoTileSpec QGeoFileTileCacheMapbox::filenameToTileSpec(const QString &filename QStringList fields = name.split('-'); int length = fields.length(); - if (length != 5 && length != 6) + if (length != 6 && length != 7) { return QGeoTileSpec(); + } else { + int scaleIdx = fields.last().indexOf("@"); + if (scaleIdx < 0 || fields.last().size() <= (scaleIdx + 2)) + return QGeoTileSpec(); + int scaleFactor = fields.last()[scaleIdx + 1].digitValue(); + if (scaleFactor != m_scaleFactor) + return QGeoTileSpec(); + } QList<int> numbers; bool ok = false; - for (int i = 2; i < length; ++i) { + for (int i = 2; i < length-1; ++i) { // skipping -@_X ok = false; int value = fields.at(i).toInt(&ok); if (!ok) diff --git a/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.h b/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.h index e96e5ab0..faf9b2bf 100644 --- a/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.h +++ b/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.h @@ -46,7 +46,7 @@ class QGeoFileTileCacheMapbox : public QGeoFileTileCache { Q_OBJECT public: - QGeoFileTileCacheMapbox(const QList<QGeoMapType> &mapTypes, const QString &directory = QString(), QObject *parent = 0); + QGeoFileTileCacheMapbox(const QList<QGeoMapType> &mapTypes, int scaleFactor, const QString &directory = QString(), QObject *parent = 0); ~QGeoFileTileCacheMapbox(); protected: @@ -55,6 +55,7 @@ protected: QList<QGeoMapType> m_mapTypes; QMap<QString, int> m_mapNameToId; + int m_scaleFactor; }; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp index de7eb4cf..30e5179e 100644 --- a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp +++ b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp @@ -116,13 +116,14 @@ QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const Q setSupportedMapTypes(mapTypes); - bool doubleRes = true; + int scaleFactor = 2; if (parameters.contains(QStringLiteral("mapbox.highdpi_tiles"))) { const QString param = parameters.value(QStringLiteral("mapbox.highdpi_tiles")).toString().toLower(); if (param == "false") - doubleRes = false; + scaleFactor = 1; } - QGeoTileFetcherMapbox *tileFetcher = new QGeoTileFetcherMapbox(this, doubleRes); + + QGeoTileFetcherMapbox *tileFetcher = new QGeoTileFetcherMapbox(scaleFactor, this); tileFetcher->setMapIds(mapIds); if (parameters.contains(QStringLiteral("useragent"))) { @@ -159,7 +160,7 @@ QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const Q // It is illegal to violate Mapbox Terms of Service, setting a limit that exceeds // what the plan the token belongs to allows. - QAbstractGeoTileCache *tileCache = new QGeoFileTileCacheMapbox(mapTypes, m_cacheDirectory); + QGeoFileTileCache *tileCache = new QGeoFileTileCacheMapbox(mapTypes, scaleFactor, m_cacheDirectory); if (parameters.contains(QStringLiteral("mapbox.cache.disk.size"))) { bool ok = false; diff --git a/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp index 6b7fc06b..062b4f89 100644 --- a/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp +++ b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp @@ -44,14 +44,14 @@ QT_BEGIN_NAMESPACE -QGeoTileFetcherMapbox::QGeoTileFetcherMapbox(QObject *parent, bool highDpiTiles) +QGeoTileFetcherMapbox::QGeoTileFetcherMapbox(int scaleFactor, QObject *parent) : QGeoTileFetcher(parent), m_networkManager(new QNetworkAccessManager(this)), m_userAgent("Qt Location based application"), m_format("png"), m_replyFormat("png"), - m_accessToken(""), - m_highDpiTiles(highDpiTiles) + m_accessToken("") { + m_scaleFactor = qBound(1, scaleFactor, 2); } void QGeoTileFetcherMapbox::setUserAgent(const QByteArray &userAgent) @@ -90,7 +90,8 @@ QGeoTiledMapReply *QGeoTileFetcherMapbox::getTileImage(const QGeoTileSpec &spec) ((spec.mapId() >= m_mapIds.size()) ? QStringLiteral("mapbox.streets") : m_mapIds[spec.mapId()]) + QLatin1Char('/') + QString::number(spec.zoom()) + QLatin1Char('/') + QString::number(spec.x()) + QLatin1Char('/') + - QString::number(spec.y()) + ((m_highDpiTiles) ? QStringLiteral("@2x.") : QStringLiteral(".")) + + QString::number(spec.y()) + + ((m_scaleFactor > 1) ? (QLatin1Char('@') + QString::number(m_scaleFactor) + QLatin1String("x.")) : QLatin1String(".")) + m_format + QLatin1Char('?') + QStringLiteral("access_token=") + m_accessToken)); diff --git a/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.h b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.h index 1263b237..e52651e1 100644 --- a/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.h +++ b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.h @@ -50,7 +50,7 @@ class QGeoTileFetcherMapbox : public QGeoTileFetcher Q_OBJECT public: - QGeoTileFetcherMapbox(QObject *parent = 0, bool highDpiTiles = true); + QGeoTileFetcherMapbox(int scaleFactor = 2, QObject *parent = 0); void setUserAgent(const QByteArray &userAgent); void setMapIds(const QVector<QString> &mapIds); @@ -66,7 +66,7 @@ private: QString m_replyFormat; QString m_accessToken; QVector<QString> m_mapIds; - bool m_highDpiTiles; + int m_scaleFactor; }; QT_END_NAMESPACE |