From 3f697f6d73f0a7f10be90f48662f139a33d1781e Mon Sep 17 00:00:00 2001 From: Wolfgang Bremer Date: Mon, 20 Apr 2015 05:09:09 +0200 Subject: Allow custom URLs for OSM tiles This enables the usage of various mapping services which use the OSM API for tile distribution. One only needs to set the urlprefix parameter to a correct url and the activeMapType to the "Custom URL Map". Task-number: QTBUG-32937 Change-Id: Ib24da19dc598ccc288047ce2651e6c1792ae2054 Reviewed-by: Alex Blasche Reviewed-by: Michal Klocek --- src/plugins/geoservices/osm/qgeotiledmaposm.cpp | 5 ++++- src/plugins/geoservices/osm/qgeotiledmaposm.h | 1 + .../geoservices/osm/qgeotiledmappingmanagerengineosm.cpp | 13 +++++++++++++ .../geoservices/osm/qgeotiledmappingmanagerengineosm.h | 4 ++++ src/plugins/geoservices/osm/qgeotilefetcherosm.cpp | 8 ++++++++ src/plugins/geoservices/osm/qgeotilefetcherosm.h | 2 ++ 6 files changed, 32 insertions(+), 1 deletion(-) (limited to 'src/plugins/geoservices') diff --git a/src/plugins/geoservices/osm/qgeotiledmaposm.cpp b/src/plugins/geoservices/osm/qgeotiledmaposm.cpp index c2407d1d..16f99cdd 100644 --- a/src/plugins/geoservices/osm/qgeotiledmaposm.cpp +++ b/src/plugins/geoservices/osm/qgeotiledmaposm.cpp @@ -39,7 +39,7 @@ QT_BEGIN_NAMESPACE QGeoTiledMapOsm::QGeoTiledMapOsm(QGeoTiledMappingManagerEngineOsm *engine, QObject *parent) -: QGeoTiledMap(engine, parent), m_mapId(-1) +: QGeoTiledMap(engine, parent), m_mapId(-1), m_customCopyright(engine->customCopyright()) { } @@ -73,6 +73,9 @@ void QGeoTiledMapOsm::evaluateCopyrights(const QSet &visibleTiles) // set attribution to Thunder Forest copyrights = tr("Maps © Thunderforest
Data © OpenStreetMap contributors"); break; + case 8: + copyrights = m_customCopyright; + break; default: // set attribution to OSM copyrights = tr("© OpenStreetMap contributors"); diff --git a/src/plugins/geoservices/osm/qgeotiledmaposm.h b/src/plugins/geoservices/osm/qgeotiledmaposm.h index 0314d9ae..86a52229 100644 --- a/src/plugins/geoservices/osm/qgeotiledmaposm.h +++ b/src/plugins/geoservices/osm/qgeotiledmaposm.h @@ -52,6 +52,7 @@ protected: private: int m_mapId; + const QString m_customCopyright; }; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp index 973a7437..873e59de 100644 --- a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp +++ b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp @@ -60,6 +60,8 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian mapTypes << QGeoMapType(QGeoMapType::TransitMap, tr("Night Transit Map"), tr("Public transit map view in night mode"), false, true, 5); mapTypes << QGeoMapType(QGeoMapType::TerrainMap, tr("Terrain Map"), tr("Terrain map view"), false, false, 6); mapTypes << QGeoMapType(QGeoMapType::PedestrianMap, tr("Hiking Map"), tr("Hiking map view"), false, false, 7); + if (parameters.contains(QStringLiteral("mapping.host"))) + mapTypes << QGeoMapType(QGeoMapType::CustomMap, tr("Custom URL Map"), tr("Custom url map view set via urlprefix parameter"), false, false, 8); setSupportedMapTypes(mapTypes); QGeoTileFetcherOsm *tileFetcher = new QGeoTileFetcherOsm(this); @@ -67,6 +69,12 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian const QByteArray ua = parameters.value(QStringLiteral("useragent")).toString().toLatin1(); tileFetcher->setUserAgent(ua); } + if (parameters.contains(QStringLiteral("mapping.host"))) { + const QString up = parameters.value(QStringLiteral("mapping.host")).toString().toLatin1(); + tileFetcher->setUrlPrefix(up); + } + if (parameters.contains(QStringLiteral("mapping.copyright"))) + m_customCopyright = parameters.value(QStringLiteral("mapping.copyright")).toString().toLatin1(); setTileFetcher(tileFetcher); @@ -83,4 +91,9 @@ QGeoMap *QGeoTiledMappingManagerEngineOsm::createMap() return new QGeoTiledMapOsm(this); } +QString QGeoTiledMappingManagerEngineOsm::customCopyright() const +{ + return m_customCopyright; +} + QT_END_NAMESPACE diff --git a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h index fab4f483..c32dbea8 100644 --- a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h +++ b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h @@ -50,6 +50,10 @@ public: ~QGeoTiledMappingManagerEngineOsm(); QGeoMap *createMap(); + QString customCopyright() const; + +private: + QString m_customCopyright; }; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/osm/qgeotilefetcherosm.cpp b/src/plugins/geoservices/osm/qgeotilefetcherosm.cpp index ad042659..95a4355e 100644 --- a/src/plugins/geoservices/osm/qgeotilefetcherosm.cpp +++ b/src/plugins/geoservices/osm/qgeotilefetcherosm.cpp @@ -51,6 +51,11 @@ void QGeoTileFetcherOsm::setUserAgent(const QByteArray &userAgent) m_userAgent = userAgent; } +void QGeoTileFetcherOsm::setUrlPrefix(const QString &urlPrefix) +{ + m_urlPrefix = urlPrefix; +} + QGeoTiledMapReply *QGeoTileFetcherOsm::getTileImage(const QGeoTileSpec &spec) { QNetworkRequest request; @@ -80,6 +85,9 @@ QGeoTiledMapReply *QGeoTileFetcherOsm::getTileImage(const QGeoTileSpec &spec) case 7: urlPrefix = QStringLiteral("http://a.tile.thunderforest.com/outdoors/"); break; + case 8: + urlPrefix = m_urlPrefix; + break; default: qWarning("Unknown map id %d\n", spec.mapId()); } diff --git a/src/plugins/geoservices/osm/qgeotilefetcherosm.h b/src/plugins/geoservices/osm/qgeotilefetcherosm.h index d36a97de..2f61f8f7 100644 --- a/src/plugins/geoservices/osm/qgeotilefetcherosm.h +++ b/src/plugins/geoservices/osm/qgeotilefetcherosm.h @@ -49,12 +49,14 @@ public: QGeoTileFetcherOsm(QObject *parent = 0); void setUserAgent(const QByteArray &userAgent); + void setUrlPrefix(const QString &urlPrefix); private: QGeoTiledMapReply *getTileImage(const QGeoTileSpec &spec); QNetworkAccessManager *m_networkManager; QByteArray m_userAgent; + QString m_urlPrefix; }; QT_END_NAMESPACE -- cgit v1.2.1