diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2017-02-07 16:17:41 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-02-08 17:21:26 +0000 |
commit | f5021281c56b660b81d0122608ca9b577889f99e (patch) | |
tree | 9e798de57b60e659f6d3bcfefd4c3af4106f68b8 /src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp | |
parent | ee453be3792d4552a86b9cbe68043396d3195d05 (diff) | |
download | qtlocation-f5021281c56b660b81d0122608ca9b577889f99e.tar.gz |
Add a default development token for Mapbox GL styles
The idea here is to have a map working zero conf, without having
to create a token. Useful for developers that want to try Mapbox GL
maps without creating an account.
The token should not be used in production (and will display a warning
telling so). It is subject to change, throttling, etc and also a
violation of the ToS.
Also fixes runtime exception when access token is not set on
mapbox:// style.
Task-number: QTBUG-58599
Change-Id: Ie7205ccbdb3ccaee753b04116aed0f5ba35f8522
Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
Diffstat (limited to 'src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp')
-rw-r--r-- | src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp index 6cbab7a2..00e088c1 100644 --- a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp +++ b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp @@ -63,6 +63,11 @@ namespace { +// WARNING! The development token is subject to Mapbox Terms of Services +// and must not be used in production. +static char developmentToken[] = + "pk.eyJ1IjoicXRzZGsiLCJhIjoiY2l5azV5MHh5MDAwdTMybzBybjUzZnhxYSJ9.9rfbeqPjX2BusLRDXHCOBA"; + static const double invLog2 = 1.0 / std::log(2.0); static double zoomLevelFrom256(double zoomLevelFor256, double tileSize) @@ -97,6 +102,7 @@ public: Q_DECLARE_FLAGS(SyncStates, SyncState); QMapboxGLSettings m_settings; + bool m_developmentMode = false; QTimer m_refresh; bool m_shouldRefresh = true; @@ -151,6 +157,9 @@ QSGNode *QGeoMapMapboxGLPrivate::updateSceneGraph(QSGNode *oldNode, QQuickWindow QMapboxGL *map = mbglNode->map(); if (m_syncState & MapTypeSync) { + m_developmentMode = m_activeMapType.name().startsWith("mapbox://") + && m_settings.accessToken() == developmentToken; + map->setStyleUrl(m_activeMapType.name()); } @@ -332,6 +341,12 @@ void QGeoMapMapboxGL::setMapboxGLSettings(const QMapboxGLSettings& settings) Q_D(QGeoMapMapboxGL); d->m_settings = settings; + + // If the access token is not set, use the development access token. + // This will only affect mapbox:// styles. + if (d->m_settings.accessToken().isEmpty()) { + d->m_settings.setAccessToken(developmentToken); + } } QSGNode *QGeoMapMapboxGL::updateSceneGraph(QSGNode *oldNode, QQuickWindow *window) @@ -375,3 +390,17 @@ void QGeoMapMapboxGL::onMapItemLineColorChange(const QColor &) d->m_mapItemsToUpdate << mapItem; } } + +void QGeoMapMapboxGL::copyrightsChanged(const QString ©rightsHtml) +{ + Q_D(QGeoMapMapboxGL); + + if (d->m_developmentMode) { + QString copyrightsHtmlDev = "<a href=\"https://www.mapbox.com/pricing/\">" + + QObject::tr("Development access token, do not use in production!") + "</a> - " + + copyrightsHtml; + QGeoMap::copyrightsChanged(copyrightsHtmlDev); + } else { + QGeoMap::copyrightsChanged(copyrightsHtml); + } +} |