Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qgeotiledmappingmanagerenginemapbox.cpp
Go to the documentation of this file.
1// Copyright (C) 2014 Canonical Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <QtLocation/private/qgeocameracapabilities_p.h>
8#include <QtLocation/private/qgeomaptype_p.h>
9#include <QtLocation/private/qgeotiledmap_p.h>
12
14
17{
18 QGeoCameraCapabilities cameraCaps;
19 cameraCaps.setMinimumZoomLevel(0.0);
20 cameraCaps.setMaximumZoomLevel(19.0);
21 cameraCaps.setSupportsBearing(true);
22 cameraCaps.setSupportsTilting(true);
23 cameraCaps.setMinimumTilt(0);
24 cameraCaps.setMaximumTilt(80);
25 cameraCaps.setMinimumFieldOfView(20.0);
26 cameraCaps.setMaximumFieldOfView(120.0);
27 cameraCaps.setOverzoomEnabled(true);
28 setCameraCapabilities(cameraCaps);
29
30 setTileSize(QSize(256, 256));
31
32 const QByteArray pluginName = "mapbox";
33 QList<QGeoMapType> mapTypes;
34 // as index 0 to retain compatibility with the current API, that expects the passed map_id to be on by default.
35 if (parameters.contains(QStringLiteral("mapbox.mapping.map_id"))) {
36 const QString name = parameters.value(QStringLiteral("mapbox.mapping.map_id")).toString();
37 mapTypes << QGeoMapType(QGeoMapType::CustomMap, name, name, false, false, mapTypes.size() + 1, pluginName, cameraCaps);
38 } else if (parameters.contains(QStringLiteral("mapbox.map_id"))) { //deprecated
39 const QString name = parameters.value(QStringLiteral("mapbox.map_id")).toString();
40 mapTypes << QGeoMapType(QGeoMapType::CustomMap, name, name, false, false, mapTypes.size() + 1, pluginName, cameraCaps);
41 }
42
43 // As of 2016.06.15, valid mapbox map_ids are documented at https://www.mapbox.com/api-documentation/#maps
44 //: Noun describing map type 'Street map'
45 mapTypes << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("mapbox.streets"), tr("Street"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
46 //: Noun describing type of a map using light colors (weak contrast)
47 mapTypes << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("mapbox.light"), tr("Light"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
48 //: Noun describing type of a map using dark colors
49 mapTypes << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("mapbox.dark"), tr("Dark"), false, true, mapTypes.size() + 1, pluginName, cameraCaps);
50 //: Noun describing type of a map created by satellite
51 mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, QStringLiteral("mapbox.satellite"), tr("Satellite"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
52 //: Noun describing type of a street map created by satellite
53 mapTypes << QGeoMapType(QGeoMapType::HybridMap, QStringLiteral("mapbox.streets-satellite"), tr("Streets Satellite"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
54 //: Noun describing type of a map using wheat paste colors
55 mapTypes << QGeoMapType(QGeoMapType::CustomMap, QStringLiteral("mapbox.wheatpaste"), tr("Wheatpaste"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
56 //: Noun describing type of a basic street map
57 mapTypes << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("mapbox.streets-basic"), tr("Streets Basic"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
58 //: Noun describing type of a map using cartoon-style fonts
59 mapTypes << QGeoMapType(QGeoMapType::CustomMap, QStringLiteral("mapbox.comic"), tr("Comic"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
60 //: Noun describing type of a map for outdoor activities
61 mapTypes << QGeoMapType(QGeoMapType::PedestrianMap, QStringLiteral("mapbox.outdoors"), tr("Outdoors"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
62 //: Noun describing type of a map for sports
63 mapTypes << QGeoMapType(QGeoMapType::CycleMap, QStringLiteral("mapbox.run-bike-hike"), tr("Run Bike Hike"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
64 //: Noun describing type of a map drawn by pencil
65 mapTypes << QGeoMapType(QGeoMapType::CustomMap, QStringLiteral("mapbox.pencil"), tr("Pencil"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
66 //: Noun describing type of a treasure map with pirate boat watermark
67 mapTypes << QGeoMapType(QGeoMapType::CustomMap, QStringLiteral("mapbox.pirates"), tr("Pirates"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
68 //: Noun describing type of a map using emerald colors
69 mapTypes << QGeoMapType(QGeoMapType::CustomMap, QStringLiteral("mapbox.emerald"), tr("Emerald"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
70 //: Noun describing type of a map with high contrast
71 mapTypes << QGeoMapType(QGeoMapType::CustomMap, QStringLiteral("mapbox.high-contrast"), tr("High Contrast"), false, false, mapTypes.size() + 1, pluginName, cameraCaps);
72
73 // New way to specify multiple customized map_ids via additional_map_ids
74 if (parameters.contains(QStringLiteral("mapbox.mapping.additional_map_ids"))) {
75 const QString ids = parameters.value(QStringLiteral("mapbox.mapping.additional_map_ids")).toString();
76 const QStringList idList = ids.split(',', Qt::SkipEmptyParts);
77
78 for (const QString &name: idList) {
79 if (!name.isEmpty())
80 mapTypes << QGeoMapType(QGeoMapType::CustomMap, name, name, false, false, mapTypes.size() + 1, pluginName, cameraCaps);
81 }
82 }
83
84 QList<QString> mapIds;
85 for (const auto &mapType : std::as_const(mapTypes))
86 mapIds.push_back(mapType.name());
87
88 setSupportedMapTypes(mapTypes);
89
90 int scaleFactor = 1;
91 if (parameters.contains(QStringLiteral("mapbox.mapping.highdpi_tiles"))) {
92 const QString param = parameters.value(QStringLiteral("mapbox.mapping.highdpi_tiles")).toString().toLower();
93 if (param == "true")
94 scaleFactor = 2;
95 }
96
98 tileFetcher->setMapIds(mapIds);
99
100 if (parameters.contains(QStringLiteral("useragent"))) {
101 const QByteArray ua = parameters.value(QStringLiteral("useragent")).toString().toLatin1();
102 tileFetcher->setUserAgent(ua);
103 }
104 if (parameters.contains(QStringLiteral("mapbox.mapping.format"))) {
105 const QString format = parameters.value(QStringLiteral("mapbox.mapping.format")).toString();
106 tileFetcher->setFormat(format);
107 } else if (parameters.contains(QStringLiteral("mapbox.format"))) { //deprecated
108 const QString format = parameters.value(QStringLiteral("mapbox.format")).toString();
109 tileFetcher->setFormat(format);
110 }
111 if (parameters.contains(QStringLiteral("mapbox.access_token"))) {
112 const QString token = parameters.value(QStringLiteral("mapbox.access_token")).toString();
113 tileFetcher->setAccessToken(token);
114 }
115
117
118 // TODO: do this in a plugin-neutral way so that other tiled map plugins
119 // don't need this boilerplate or hardcode plugin name
120
121 if (parameters.contains(QStringLiteral("mapbox.mapping.cache.directory"))) {
122 m_cacheDirectory = parameters.value(QStringLiteral("mapbox.mapping.cache.directory")).toString();
123 } else {
124 // managerName() is not yet set, we have to hardcode the plugin name below
125 m_cacheDirectory = QAbstractGeoTileCache::baseLocationCacheDirectory() + QLatin1String(pluginName);
126 }
127
128 QGeoFileTileCache *tileCache = new QGeoFileTileCacheMapbox(mapTypes, scaleFactor, m_cacheDirectory);
129
130 /*
131 * Disk cache setup -- defaults to Unitary since:
132 *
133 * The Mapbox free plan allows for 6000 tiles to be stored for offline uses,
134 * As of 2016.06.15, according to https://www.mapbox.com/help/mobile-offline/ .
135 * Thus defaulting to Unitary strategy, and setting 6000 tiles as default cache disk size
136 */
137 if (parameters.contains(QStringLiteral("mapbox.mapping.cache.disk.cost_strategy"))) {
138 QString cacheStrategy = parameters.value(QStringLiteral("mapbox.mapping.cache.disk.cost_strategy")).toString().toLower();
139 if (cacheStrategy == QLatin1String("bytesize"))
141 else
143 } else {
145 }
146 if (parameters.contains(QStringLiteral("mapbox.mapping.cache.disk.size"))) {
147 bool ok = false;
148 int cacheSize = parameters.value(QStringLiteral("mapbox.mapping.cache.disk.size")).toString().toInt(&ok);
149 if (ok)
151 } else {
153 tileCache->setMaxDiskUsage(6000); // The maximum allowed with the free tier
154 }
155
156 /*
157 * Memory cache setup -- defaults to ByteSize (old behavior)
158 */
159 if (parameters.contains(QStringLiteral("mapbox.mapping.cache.memory.cost_strategy"))) {
160 QString cacheStrategy = parameters.value(QStringLiteral("mapbox.mapping.cache.memory.cost_strategy")).toString().toLower();
161 if (cacheStrategy == QLatin1String("bytesize"))
163 else
165 } else {
167 }
168 if (parameters.contains(QStringLiteral("mapbox.mapping.cache.memory.size"))) {
169 bool ok = false;
170 int cacheSize = parameters.value(QStringLiteral("mapbox.mapping.cache.memory.size")).toString().toInt(&ok);
171 if (ok)
173 }
174
175 /*
176 * Texture cache setup -- defaults to ByteSize (old behavior)
177 */
178 if (parameters.contains(QStringLiteral("mapbox.mapping.cache.texture.cost_strategy"))) {
179 QString cacheStrategy = parameters.value(QStringLiteral("mapbox.mapping.cache.texture.cost_strategy")).toString().toLower();
180 if (cacheStrategy == QLatin1String("bytesize"))
182 else
184 } else {
186 }
187 if (parameters.contains(QStringLiteral("mapbox.mapping.cache.texture.size"))) {
188 bool ok = false;
189 int cacheSize = parameters.value(QStringLiteral("mapbox.mapping.cache.texture.size")).toString().toInt(&ok);
190 if (ok)
192 }
193
194 /* PREFETCHING */
195 if (parameters.contains(QStringLiteral("mapbox.mapping.prefetching_style"))) {
196 const QString prefetchingMode = parameters.value(QStringLiteral("mapbox.mapping.prefetching_style")).toString();
197 if (prefetchingMode == QStringLiteral("TwoNeighbourLayers"))
199 else if (prefetchingMode == QStringLiteral("OneNeighbourLayer"))
201 else if (prefetchingMode == QStringLiteral("NoPrefetching"))
203 }
204
206
208 errorString->clear();
209}
210
212{
213}
214
216{
217 QGeoTiledMap *map = new Map(this, 0);
218 map->setPrefetchStyle(m_prefetchStyle);
219 return map;
220}
221
virtual void setMaxDiskUsage(int diskUsage)
static QString baseLocationCacheDirectory()
virtual CostStrategy costStrategyDisk() const =0
virtual void setMaxMemoryUsage(int memoryUsage)
virtual void setCostStrategyDisk(CostStrategy costStrategy)=0
virtual void setCostStrategyMemory(CostStrategy costStrategy)=0
virtual void setCostStrategyTexture(CostStrategy costStrategy)=0
virtual void setExtraTextureUsage(int textureUsage)=0
\inmodule QtCore
Definition qbytearray.h:57
void setSupportsBearing(bool supportsBearing)
Sets whether the associated plugin can render a map when the camera has an arbitrary bearing to suppo...
void setMaximumZoomLevel(double maximumZoomLevel)
void setMaximumTilt(double maximumTilt)
void setMaximumFieldOfView(double maximumFieldOfView)
void setMinimumFieldOfView(double minimumFieldOfView)
void setOverzoomEnabled(bool overzoomEnabled)
Sets whether overzooming is supported by the associated plugin.
void setMinimumTilt(double minimumTilt)
void setMinimumZoomLevel(double minimumZoomLevel)
void setSupportsTilting(bool supportsTilting)
Sets whether the associated plugin can render a map when the camera is tilted to supportsTilting.
void setCameraCapabilities(const QGeoCameraCapabilities &capabilities)
void setSupportedMapTypes(const QList< QGeoMapType > &supportedMapTypes)
Sets the list of map types supported by this engine to mapTypes.
QVariantMap parameters() const
Error
Describes an error related to the loading and setup of a service provider plugin.
QGeoTiledMappingManagerEngineMapbox(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString)
void setTileFetcher(QGeoTileFetcher *fetcher)
Sets the tile fetcher.
void setTileCache(QAbstractGeoTileCache *cache)
Sets the tile cache.
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
void push_back(parameter_type t)
Definition qlist.h:672
T value(const Key &key, const T &defaultValue=T()) const
Definition qmap.h:356
bool contains(const Key &key) const
Definition qmap.h:340
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QByteArray toLatin1() const &
Definition qstring.h:559
int toInt(bool *ok=nullptr, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition qstring.h:660
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1107
QString toLower() const &
Definition qstring.h:368
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
QMap< QString, QString > map
[6]
Token token
Definition keywords.cpp:444
Combined button and popup list for selecting options.
@ SkipEmptyParts
Definition qnamespace.h:127
DBusConnection const char DBusError * error
GLenum GLenum GLsizei const GLuint * ids
GLenum const GLint * param
GLuint name
GLint GLsizei GLsizei GLenum format
static quint64 cacheSize()
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
#define tr(X)
QList< QPair< QString, QString > > Map