Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgeotiledmappingmanagerengineohosmapkit.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtCore/private/qohoscommon_p.h>
5#include <QtCore/private/qohoslogger_p.h>
6#include <QtLocation/private/qgeocameracapabilities_p.h>
7#include <QtLocation/private/qgeofiletilecache_p.h>
8#include <QtLocation/private/qgeomaptype_p.h>
9#include <QtLocation/private/qgeotiledmap_p.h>
10#include <qgeofiletilecacheohosmapkit.h>
11#include <qgeotiledmappingmanagerengineohosmapkit.h>
12#include <qgeotilefetcherohosmapkit.h>
13#include <qohosmapkitcommon.h>
14
16
17namespace {
18
19const QByteArray pluginName = "ohosmapkit";
20
21constexpr double ohosMinimumZoomLevel = 1.0;
22constexpr double ohosMaximumZoomLevel = 20.0;
23constexpr QSize lowDpiTileSize = {256, 256};
24constexpr int mapId = 0;
25
26const QString highDpiParameterName = QStringLiteral("ohosmapkit.mapping.highdpi_tiles");
27const QString cacheDirectoryParameterName = QStringLiteral("ohosmapkit.mapping.cache.directory");
28const QString cacheDiskCostStrategyParameterName = QStringLiteral("ohosmapkit.mapping.cache.disk.cost_strategy");
29const QString cacheDiskSizeParameterName = QStringLiteral("ohosmapkit.mapping.cache.disk.size");
30const QString cacheMemoryCostStrategyParameterName = QStringLiteral("ohosmapkit.mapping.cache.memory.cost_strategy");
31const QString cacheMemorySizeParameterName = QStringLiteral("ohosmapkit.mapping.cache.memory.size");
32const QString cacheTextureCostStrategyParameterName = QStringLiteral("ohosmapkit.mapping.cache.texture.cost_strategy");
33const QString cacheTextureSizeParameterName = QStringLiteral("ohosmapkit.mapping.cache.texture.size");
34const QString prefetchingStyleParameterName = QStringLiteral("ohosmapkit.mapping.prefetching_style");
35
37 const QVariantMap &parameters, const QString &parameterName)
38{
39 return parameters.contains(parameterName)
40 && parameters.value(parameterName).toString().toLower() == QLatin1String("bytesize")
41 ? QGeoFileTileCache::ByteSize
42 : QGeoFileTileCache::Unitary;
43}
44
46 const QVariantMap &parameters, const QString &parameterName, const QOhosConsumer<int> &parameterConsumer)
47{
48 if (!parameters.contains(parameterName))
49 return;
50
51 bool ok = false;
52 int cacheSize = parameters.value(parameterName).toInt(&ok);
53 if (ok) {
54 parameterConsumer(cacheSize);
55 } else {
56 qOhosPrintfWarning(
57 "%s: Parameter %s value cannot be converted to int.",
58 Q_FUNC_INFO, parameterName.toStdString().c_str());
59 }
60}
61
62void configureFileTileCache(QGeoFileTileCache *tileCache, const QVariantMap &parameters)
63{
64 tileCache->setCostStrategyDisk(
65 getCacheCostStrategy(parameters, cacheDiskCostStrategyParameterName));
66 tryExtractIntParameter(
67 parameters, cacheDiskSizeParameterName,
68 [&](int cacheSize) {
69 tileCache->setMaxDiskUsage(cacheSize);
70 });
71
72 tileCache->setCostStrategyMemory(
73 getCacheCostStrategy(parameters, cacheMemoryCostStrategyParameterName));
74 tryExtractIntParameter(
75 parameters, cacheMemorySizeParameterName,
76 [&](int cacheSize) {
77 tileCache->setMaxMemoryUsage(cacheSize);
78 });
79
80 tileCache->setCostStrategyTexture(
81 getCacheCostStrategy(parameters, cacheTextureCostStrategyParameterName));
82 tryExtractIntParameter(
83 parameters, cacheTextureSizeParameterName,
84 [&](int cacheSize) {
85 tileCache->setExtraTextureUsage(cacheSize);
86 });
87}
88
89int getScaleFactor(const QVariantMap &parameters)
90{
91 constexpr int lowDpiScaleFactor = 1;
92 constexpr int highDpiScaleFactor = 2;
93
94 return parameters.contains(highDpiParameterName)
95 && parameters.value(highDpiParameterName).toBool()
96 ? highDpiScaleFactor
97 : lowDpiScaleFactor;
98}
99
101{
102public:
104 const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString);
105
106private:
107 QGeoMap *createMap() override;
108};
109
111 const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString)
113{
114 QGeoCameraCapabilities cameraCapabilities;
115 cameraCapabilities.setMinimumZoomLevel(ohosMinimumZoomLevel);
116 cameraCapabilities.setMaximumZoomLevel(ohosMaximumZoomLevel);
117 cameraCapabilities.setSupportsBearing(true);
118 cameraCapabilities.setSupportsTilting(true);
119 cameraCapabilities.setOverzoomEnabled(true);
120 setCameraCapabilities(cameraCapabilities);
121
122 setSupportedMapTypes(
123 {
124 QGeoMapType(
125 QGeoMapType::StreetMap, QStringLiteral("ohosmapkit.streets"), tr("Street"), false, false,
126 mapId, pluginName, cameraCapabilities)
127 });
128
129 const auto scaleFactor = getScaleFactor(parameters);
130 setTileSize(lowDpiTileSize * scaleFactor);
131
132 setTileFetcher(
133 makeGeoTileFetcherOhosMapKit(
134 OhosMapKit::getAuthenticationKeyParameterOrEmpty(parameters),
135 OhosMapKit::getUserAgentParameterOrDefault(parameters),
136 scaleFactor, this));
137
138 auto *tileCache =
139 makeGeoFileTileCacheOhosMapKit(
140 scaleFactor,
141 parameters.contains(cacheDirectoryParameterName)
142 ? parameters.value(cacheDirectoryParameterName).toString()
143 : QAbstractGeoTileCache::baseLocationCacheDirectory() + QLatin1String(pluginName),
144 this);
145 configureFileTileCache(tileCache, parameters);
146 setTileCache(tileCache);
147
148 if (parameters.contains(prefetchingStyleParameterName)) {
149 const QString prefetchingMode = parameters.value(prefetchingStyleParameterName).toString();
150 if (prefetchingMode == QStringLiteral("TwoNeighbourLayers"))
151 m_prefetchStyle = QGeoTiledMap::PrefetchTwoNeighbourLayers;
152 else if (prefetchingMode == QStringLiteral("OneNeighbourLayer"))
153 m_prefetchStyle = QGeoTiledMap::PrefetchNeighbourLayer;
154 else if (prefetchingMode == QStringLiteral("NoPrefetching"))
155 m_prefetchStyle = QGeoTiledMap::NoPrefetching;
156 }
157
158 if (error != nullptr)
159 *error = QGeoServiceProvider::NoError;
160
161 if (errorString != nullptr)
162 errorString->clear();
163}
164
166{
167 auto *map = new QGeoTiledMap(this, nullptr);
168 map->setPrefetchStyle(m_prefetchStyle);
169 return map;
170}
171
172}
173
175 const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString)
176{
177 return new QGeoTiledMappingManagerEngineOhosMapKit(parameters, error, errorString);
178}
179
180QT_END_NAMESPACE
QGeoTiledMappingManagerEngineOhosMapKit(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString)
Combined button and popup list for selecting options.
int getScaleFactor(const QVariantMap &parameters)
void configureFileTileCache(QGeoFileTileCache *tileCache, const QVariantMap &parameters)
QAbstractGeoTileCache::CostStrategy getCacheCostStrategy(const QVariantMap &parameters, const QString &parameterName)
void tryExtractIntParameter(const QVariantMap &parameters, const QString &parameterName, const QOhosConsumer< int > &parameterConsumer)
QGeoTiledMappingManagerEngine * makeQGeoTiledMappingManagerEngineOhosMapKit(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString)