diff options
author | Paolo Angelelli <paolo.angelelli@theqtcompany.com> | 2016-06-28 16:27:09 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@theqtcompany.com> | 2016-07-01 09:29:11 +0000 |
commit | c2329ca8fb48aac7da1694f4b9c3d28924feae63 (patch) | |
tree | 4031363229220cf4617f689799340013b9fa091a | |
parent | a10b6b5bf6ed29f705c2e3dd85c1206a96171f60 (diff) | |
download | qtlocation-c2329ca8fb48aac7da1694f4b9c3d28924feae63.tar.gz |
Use HiDpi tiles to produce crisper maps at fractional zoom levels
The current QtLocation renderer uses geotiles of specified size for
each specific zoom level, and show them using nearest neighbor
interpolation when the camera is at that specific zoom level.
Interpolation is changed to linear when the zoom level is in between
two neighboring tile layers, but hasn't reached the next yet, so that
the previous layer can be magnified smoothly.
While this is the correct approach, it produces blurry images most of
the time, while the previous camera mechanics, not allowing continuous
zoom, was able to show crisp images all the time.
To retain the continuous zoom and produce crisp images, this patch
makes use of HiDpi tiles from providers that offer them (HERE and
mapbox).
The way these two providers offer HiDpi is different: HERE scales the
map elements (text, mostly), to address a specific dpi (supported
dpis are 72, the standard, 250, 320, 500), while mapbox returns
the same tile at double resolution.
The way the patch deals with this is by taking the image requested
as is, but setting the tile size in the renderer to be half of that,
while at the same time enabling mip mapping for QSGImageNodes.
In this way, at integer zoom level, texture LOD 1 is shown, that is
an OpenGL-scaled-down version of the downloaded tile, while at the
other fractional zoom levels trilinear interpolation is used to
produce a good image.
This approach was not possible for the openstreetmap geoservice
provider because mapquest (the currently used data provider) does
not offer HiDpi tiles, and a scaled version of the standard tile
would make the text unreadable half of the times.
Further scaling would be possible, e.g., with HERE maps, offering
500ppi maps, to look good during scaling also on HiDpi devices.
This can be addressed in a future patch.
Task-number: QTBUG-53318
Task-number: QTBUG-48868
Task-number: QTBUG-36949
Change-Id: Iaa6f5b1ece9d37a0c85e73efaf1bd3b50b1d5950
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
9 files changed, 52 insertions, 21 deletions
diff --git a/src/location/doc/src/plugins/mapbox.qdoc b/src/location/doc/src/plugins/mapbox.qdoc index 0b989218..449df330 100644 --- a/src/location/doc/src/plugins/mapbox.qdoc +++ b/src/location/doc/src/plugins/mapbox.qdoc @@ -80,6 +80,9 @@ The following table lists optional parameters that can be passed to the Mapbox p "jpg70", "jpg80", "jpg90" (JPEG with 70%, 80% and 90% compression). Defaults to "png". \row + \li mapbox.highdpi_tiles + \li Whether or not to request high dpi tiles. Valid values are \b true and \b false. The default value is \b true. +\row \li useragent \li User agent string set when making network requests. \row diff --git a/src/location/doc/src/plugins/nokia.qdoc b/src/location/doc/src/plugins/nokia.qdoc index 1ed5e6e1..c13cec36 100644 --- a/src/location/doc/src/plugins/nokia.qdoc +++ b/src/location/doc/src/plugins/nokia.qdoc @@ -105,6 +105,9 @@ a prefix. \li here.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. \row + \li here.mapping.highdpi_tiles + \li Whether or not to request high dpi tiles. Valid values are \b true and \b false. The default value is \b true. +\row \li here.geocoding.host \li Geocoding service URL used by geocoding manager. \row diff --git a/src/location/maps/qgeotiledmapscene.cpp b/src/location/maps/qgeotiledmapscene.cpp index c7e5bed0..3644cab6 100644 --- a/src/location/maps/qgeotiledmapscene.cpp +++ b/src/location/maps/qgeotiledmapscene.cpp @@ -677,6 +677,8 @@ void QGeoTiledMapRootNode::updateTiles(QGeoTiledMapTileContainerNode *root, } else { if (isTextureLinear != d->m_linearScaling) { node->setFiltering(d->m_linearScaling ? QSGTexture::Linear : QSGTexture::Nearest); + if (node->texture()->textureSize().width() > d->m_tileSize) + node->setMipmapFiltering(QSGTexture::Linear); dirtyBits |= QSGNode::DirtyMaterial; } if (dirtyBits != 0) @@ -698,6 +700,8 @@ void QGeoTiledMapRootNode::updateTiles(QGeoTiledMapTileContainerNode *root, if (d->buildGeometry(s, tileNode->geometry()->vertexDataAsTexturedPoint2D()) && qgeotiledmapscene_isTileInViewport(tileNode->geometry()->vertexDataAsTexturedPoint2D(), root->matrix())) { tileNode->setFiltering(d->m_linearScaling ? QSGTexture::Linear : QSGTexture::Nearest); + if (tileNode->texture()->textureSize().width() > d->m_tileSize) + tileNode->setMipmapFiltering(QSGTexture::Linear); root->addChild(s, tileNode); } else { delete tileNode; diff --git a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp index ea679afc..eb1ad866 100644 --- a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp +++ b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp @@ -116,8 +116,13 @@ QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const Q setSupportedMapTypes(mapTypes); - QGeoTileFetcherMapbox *tileFetcher = new QGeoTileFetcherMapbox(this); - tileFetcher->setMapIds(mapIds); + bool doubleRes = true; + if (parameters.contains(QStringLiteral("mapbox.highdpi_tiles"))) { + const QString param = parameters.value(QStringLiteral("mapbox.highdpi_tiles")).toString().toLower(); + if (param == "false") + doubleRes = false; + } + QGeoTileFetcherMapbox *tileFetcher = new QGeoTileFetcherMapbox(this, doubleRes); if (parameters.contains(QStringLiteral("useragent"))) { const QByteArray ua = parameters.value(QStringLiteral("useragent")).toString().toLatin1(); diff --git a/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp index 7a082006..6b7fc06b 100644 --- a/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp +++ b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp @@ -44,12 +44,13 @@ QT_BEGIN_NAMESPACE -QGeoTileFetcherMapbox::QGeoTileFetcherMapbox(QObject *parent) +QGeoTileFetcherMapbox::QGeoTileFetcherMapbox(QObject *parent, bool highDpiTiles) : QGeoTileFetcher(parent), m_networkManager(new QNetworkAccessManager(this)), m_userAgent("Qt Location based application"), m_format("png"), m_replyFormat("png"), - m_accessToken("") + m_accessToken(""), + m_highDpiTiles(highDpiTiles) { } @@ -89,7 +90,7 @@ 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()) + QLatin1Char('.') + + QString::number(spec.y()) + ((m_highDpiTiles) ? QStringLiteral("@2x.") : QStringLiteral(".")) + 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 a1ab7dcc..1263b237 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); + QGeoTileFetcherMapbox(QObject *parent = 0, bool highDpiTiles = true); void setUserAgent(const QByteArray &userAgent); void setMapIds(const QVector<QString> &mapIds); @@ -66,6 +66,7 @@ private: QString m_replyFormat; QString m_accessToken; QVector<QString> m_mapIds; + bool m_highDpiTiles; }; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp index 4f44e5fd..64449d1d 100644 --- a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp +++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp @@ -95,7 +95,14 @@ QGeoTiledMappingManagerEngineNokia::QGeoTiledMappingManagerEngineNokia( types << QGeoMapType(QGeoMapType::CarNavigationMap, tr("Car Navigation Map"), tr("Normal map view in daylight mode for car navigation"), false, false, 21); setSupportedMapTypes(types); - QGeoTileFetcherNokia *fetcher = new QGeoTileFetcherNokia(parameters, networkManager, this, tileSize()); + int ppi = 250; + if (parameters.contains(QStringLiteral("here.mapping.highdpi_tiles"))) { + const QString param = parameters.value(QStringLiteral("here.mapping.highdpi_tiles")).toString().toLower(); + if (param == "false") + ppi = 72; + } + + QGeoTileFetcherNokia *fetcher = new QGeoTileFetcherNokia(parameters, networkManager, this, tileSize(), ppi); setTileFetcher(fetcher); // TODO: do this in a plugin-neutral way so that other tiled map plugins diff --git a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp index 50acc2a0..a55f71c0 100644 --- a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp +++ b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp @@ -56,11 +56,11 @@ QT_BEGIN_NAMESPACE namespace { - QString sizeToStr(const QSize &size) + QString sizeToStr(int size) { - if (size.height() >= 512 || size.width() >= 512) + if (size > 256) return QStringLiteral("512"); - else if (size.height() >= 256 || size.width() >= 256) + else if (size > 128) return QStringLiteral("256"); else return QStringLiteral("128"); // 128 pixel tiles are deprecated. @@ -74,13 +74,14 @@ namespace QGeoTileFetcherNokia::QGeoTileFetcherNokia(const QVariantMap ¶meters, QGeoNetworkAccessManager *networkManager, QGeoTiledMappingManagerEngineNokia *engine, - const QSize &tileSize) -: QGeoTileFetcher(engine), m_engineNokia(engine), m_networkManager(networkManager), - m_tileSize(tileSize), m_copyrightsReply(0), + const QSize &tileSize, + int ppi) +: QGeoTileFetcher(engine), m_engineNokia(engine), m_networkManager(networkManager), m_ppi(ppi), m_copyrightsReply(0), m_baseUriProvider(new QGeoUriProvider(this, parameters, QStringLiteral("here.mapping.host"), MAP_TILES_HOST)), m_aerialUriProvider(new QGeoUriProvider(this, parameters, QStringLiteral("here.mapping.host.aerial"), MAP_TILES_HOST_AERIAL)) { Q_ASSERT(networkManager); + m_tileSize = qMax(tileSize.width(), tileSize.height()); m_networkManager->setParent(this); m_applicationId = parameters.value(QStringLiteral("here.app_id")).toString(); @@ -94,7 +95,11 @@ QGeoTileFetcherNokia::~QGeoTileFetcherNokia() QGeoTiledMapReply *QGeoTileFetcherNokia::getTileImage(const QGeoTileSpec &spec) { // TODO add error detection for if request.connectivityMode() != QGraphicsGeoMap::OnlineMode - QString rawRequest = getRequestString(spec); + int ppi = m_ppi; + if ((spec.mapId() == 2) || (spec.mapId() == 12) || (spec.mapId() == 21)) + ppi = 72; // HiDpi apparently not supported for these maps + + QString rawRequest = getRequestString(spec, ppi); if (rawRequest.isEmpty()) { return new QGeoTiledMapReply(QGeoTiledMapReply::UnknownError, tr("Mapping manager no longer exists"), this); @@ -110,7 +115,7 @@ QGeoTiledMapReply *QGeoTileFetcherNokia::getTileImage(const QGeoTileSpec &spec) return mapReply; } -QString QGeoTileFetcherNokia::getRequestString(const QGeoTileSpec &spec) +QString QGeoTileFetcherNokia::getRequestString(const QGeoTileSpec &spec, int ppi) { if (!m_engineNokia) return QString(); @@ -136,11 +141,11 @@ QString QGeoTileFetcherNokia::getRequestString(const QGeoTileSpec &spec) requestString += slash; requestString += QString::number(spec.y()); requestString += slash; - requestString += sizeToStr(m_tileSize); + requestString += ((ppi > 72)) ? sizeToStr(m_tileSize * 2) : sizeToStr(m_tileSize); static const QString slashpng("/png8"); requestString += slashpng; - if (!m_token.isEmpty() && !m_applicationId.isEmpty()) { + if (!m_token.isEmpty() && !m_applicationId.isEmpty()) { // TODO: remove the if requestString += "?token="; requestString += m_token; @@ -148,9 +153,10 @@ QString QGeoTileFetcherNokia::getRequestString(const QGeoTileSpec &spec) requestString += m_applicationId; } + requestString += "&ppi=" + QString::number(ppi); + requestString += "&lg="; requestString += getLanguageString(); - return requestString; } diff --git a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h index 44f2ad07..06d1bba9 100644 --- a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h +++ b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h @@ -57,7 +57,7 @@ class QGeoTileFetcherNokia : public QGeoTileFetcher public: QGeoTileFetcherNokia(const QVariantMap ¶meters, QGeoNetworkAccessManager *networkManager, - QGeoTiledMappingManagerEngineNokia *engine, const QSize &tileSize); + QGeoTiledMappingManagerEngineNokia *engine, const QSize &tileSize, int ppi); ~QGeoTileFetcherNokia(); QGeoTiledMapReply *getTileImage(const QGeoTileSpec &spec); @@ -74,13 +74,14 @@ public Q_SLOTS: private: Q_DISABLE_COPY(QGeoTileFetcherNokia) - QString getRequestString(const QGeoTileSpec &spec); + QString getRequestString(const QGeoTileSpec &spec, int ppi=72); QString getLanguageString() const; QPointer<QGeoTiledMappingManagerEngineNokia> m_engineNokia; QGeoNetworkAccessManager *m_networkManager; - QSize m_tileSize; + int m_tileSize; + int m_ppi; QString m_token; QNetworkReply *m_copyrightsReply; QNetworkReply *m_versionReply; |