15QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(
const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString)
16: QGeoTiledMappingManagerEngine()
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);
30 setTileSize(QSize(256, 256));
32 const QByteArray pluginName =
"mapbox";
33 QList<QGeoMapType> mapTypes;
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"))) {
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);
45 mapTypes << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral(
"mapbox.streets"), tr(
"Street"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
47 mapTypes << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral(
"mapbox.light"), tr(
"Light"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
49 mapTypes << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral(
"mapbox.dark"), tr(
"Dark"),
false,
true, mapTypes.size() + 1, pluginName, cameraCaps);
51 mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, QStringLiteral(
"mapbox.satellite"), tr(
"Satellite"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
53 mapTypes << QGeoMapType(QGeoMapType::HybridMap, QStringLiteral(
"mapbox.streets-satellite"), tr(
"Streets Satellite"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
55 mapTypes << QGeoMapType(QGeoMapType::CustomMap, QStringLiteral(
"mapbox.wheatpaste"), tr(
"Wheatpaste"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
57 mapTypes << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral(
"mapbox.streets-basic"), tr(
"Streets Basic"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
59 mapTypes << QGeoMapType(QGeoMapType::CustomMap, QStringLiteral(
"mapbox.comic"), tr(
"Comic"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
61 mapTypes << QGeoMapType(QGeoMapType::PedestrianMap, QStringLiteral(
"mapbox.outdoors"), tr(
"Outdoors"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
63 mapTypes << QGeoMapType(QGeoMapType::CycleMap, QStringLiteral(
"mapbox.run-bike-hike"), tr(
"Run Bike Hike"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
65 mapTypes << QGeoMapType(QGeoMapType::CustomMap, QStringLiteral(
"mapbox.pencil"), tr(
"Pencil"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
67 mapTypes << QGeoMapType(QGeoMapType::CustomMap, QStringLiteral(
"mapbox.pirates"), tr(
"Pirates"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
69 mapTypes << QGeoMapType(QGeoMapType::CustomMap, QStringLiteral(
"mapbox.emerald"), tr(
"Emerald"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
71 mapTypes << QGeoMapType(QGeoMapType::CustomMap, QStringLiteral(
"mapbox.high-contrast"), tr(
"High Contrast"),
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
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);
78 for (
const QString &name: idList) {
80 mapTypes << QGeoMapType(QGeoMapType::CustomMap, name, name,
false,
false, mapTypes.size() + 1, pluginName, cameraCaps);
84 QList<QString> mapIds;
85 for (
const auto &mapType : std::as_const(mapTypes))
86 mapIds.push_back(mapType.name());
88 setSupportedMapTypes(mapTypes);
91 if (parameters.contains(QStringLiteral(
"mapbox.mapping.highdpi_tiles"))) {
92 const QString param = parameters.value(QStringLiteral(
"mapbox.mapping.highdpi_tiles")).toString().toLower();
97 QGeoTileFetcherMapbox *tileFetcher =
new QGeoTileFetcherMapbox(scaleFactor,
this);
98 tileFetcher->setMapIds(mapIds);
100 if (parameters.contains(QStringLiteral(
"useragent"))) {
101 const QByteArray ua = parameters.value(QStringLiteral(
"useragent")).toString().toLatin1();
102 tileFetcher->setUserAgent(ua);
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"))) {
108 const QString format = parameters.value(QStringLiteral(
"mapbox.format")).toString();
109 tileFetcher->setFormat(format);
111 if (parameters.contains(QStringLiteral(
"mapbox.access_token"))) {
112 const QString token = parameters.value(QStringLiteral(
"mapbox.access_token")).toString();
113 tileFetcher->setAccessToken(token);
116 setTileFetcher(tileFetcher);
121 if (parameters.contains(QStringLiteral(
"mapbox.mapping.cache.directory"))) {
122 m_cacheDirectory = parameters.value(QStringLiteral(
"mapbox.mapping.cache.directory")).toString();
125 m_cacheDirectory = QAbstractGeoTileCache::baseLocationCacheDirectory() + QLatin1String(pluginName);
128 QGeoFileTileCache *tileCache =
new QGeoFileTileCacheMapbox(mapTypes, scaleFactor, m_cacheDirectory);
131
132
133
134
135
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"))
140 tileCache->setCostStrategyDisk(QGeoFileTileCache::ByteSize);
142 tileCache->setCostStrategyDisk(QGeoFileTileCache::Unitary);
144 tileCache->setCostStrategyDisk(QGeoFileTileCache::Unitary);
146 if (parameters.contains(QStringLiteral(
"mapbox.mapping.cache.disk.size"))) {
148 int cacheSize = parameters.value(QStringLiteral(
"mapbox.mapping.cache.disk.size")).toString().toInt(&ok);
150 tileCache->setMaxDiskUsage(cacheSize);
152 if (tileCache->costStrategyDisk() == QGeoFileTileCache::Unitary)
153 tileCache->setMaxDiskUsage(6000);
157
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"))
162 tileCache->setCostStrategyMemory(QGeoFileTileCache::ByteSize);
164 tileCache->setCostStrategyMemory(QGeoFileTileCache::Unitary);
166 tileCache->setCostStrategyMemory(QGeoFileTileCache::ByteSize);
168 if (parameters.contains(QStringLiteral(
"mapbox.mapping.cache.memory.size"))) {
170 int cacheSize = parameters.value(QStringLiteral(
"mapbox.mapping.cache.memory.size")).toString().toInt(&ok);
172 tileCache->setMaxMemoryUsage(cacheSize);
176
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"))
181 tileCache->setCostStrategyTexture(QGeoFileTileCache::ByteSize);
183 tileCache->setCostStrategyTexture(QGeoFileTileCache::Unitary);
185 tileCache->setCostStrategyTexture(QGeoFileTileCache::ByteSize);
187 if (parameters.contains(QStringLiteral(
"mapbox.mapping.cache.texture.size"))) {
189 int cacheSize = parameters.value(QStringLiteral(
"mapbox.mapping.cache.texture.size")).toString().toInt(&ok);
191 tileCache->setExtraTextureUsage(cacheSize);
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"))
198 m_prefetchStyle = QGeoTiledMap::PrefetchTwoNeighbourLayers;
199 else if (prefetchingMode == QStringLiteral(
"OneNeighbourLayer"))
200 m_prefetchStyle = QGeoTiledMap::PrefetchNeighbourLayer;
201 else if (prefetchingMode == QStringLiteral(
"NoPrefetching"))
202 m_prefetchStyle = QGeoTiledMap::NoPrefetching;
205 setTileCache(tileCache);
207 *error = QGeoServiceProvider::NoError;
208 errorString->clear();