QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCMapUrlEngine.cpp
Go to the documentation of this file.
1#include "QGCMapUrlEngine.h"
2
3#include "QGCTileSet.h"
4
5#include <QtCore/QtMinMax>
6#include <QtCore/QUrl>
7
8#include "BingMapProvider.h"
10#include "EsriMapProvider.h"
11#include "GenericMapProvider.h"
12#include "GoogleMapProvider.h"
13#include "MapboxMapProvider.h"
14#include "TianDiTuProvider.h"
15#include "QGCLoggingCategory.h"
16
17QGC_LOGGING_CATEGORY(QGCMapUrlEngineLog, "QtLocationPlugin.QGCMapUrlEngine")
18
19const QList<SharedMapProvider> UrlFactory::_providers = {
20#ifndef QGC_NO_GOOGLE_MAPS
21 std::make_shared<GoogleStreetMapProvider>(),
22 std::make_shared<GoogleSatelliteMapProvider>(),
23 std::make_shared<GoogleTerrainMapProvider>(),
24 std::make_shared<GoogleHybridMapProvider>(),
25 std::make_shared<GoogleLabelsMapProvider>(),
26#endif
27 std::make_shared<BingRoadMapProvider>(),
28 std::make_shared<BingSatelliteMapProvider>(),
29 std::make_shared<BingHybridMapProvider>(),
30
31 std::make_shared<TianDiTuRoadProvider>(),
32 std::make_shared<TianDiTuSatelliteProvider>(),
33 std::make_shared<StatkartTopoMapProvider>(),
34 std::make_shared<StatkartBaseMapProvider>(),
35 std::make_shared<SvalbardMapProvider>(),
36
37 std::make_shared<EniroMapProvider>(),
38
39 std::make_shared<EsriWorldStreetMapProvider>(),
40 std::make_shared<EsriWorldSatelliteMapProvider>(),
41 std::make_shared<EsriTerrainMapProvider>(),
42
43 std::make_shared<MapboxStreetMapProvider>(),
44 std::make_shared<MapboxLightMapProvider>(),
45 std::make_shared<MapboxDarkMapProvider>(),
46 std::make_shared<MapboxSatelliteMapProvider>(),
47 std::make_shared<MapboxHybridMapProvider>(),
48 std::make_shared<MapboxStreetsBasicMapProvider>(),
49 std::make_shared<MapboxOutdoorsMapProvider>(),
50 std::make_shared<MapboxBrightMapProvider>(),
51 std::make_shared<MapboxCustomMapProvider>(),
52
53 std::make_shared<MapQuestMapMapProvider>(),
54 std::make_shared<MapQuestSatMapProvider>(),
55
56 std::make_shared<VWorldStreetMapProvider>(),
57 std::make_shared<VWorldSatMapProvider>(),
58
59 std::make_shared<JapanStdMapProvider>(),
60 std::make_shared<JapanSeamlessMapProvider>(),
61 std::make_shared<JapanAnaglyphMapProvider>(),
62 std::make_shared<JapanSlopeMapProvider>(),
63 std::make_shared<JapanReliefMapProvider>(),
64
65 std::make_shared<LINZBasemapMapProvider>(),
66
67 std::make_shared<OpenStreetMapProvider>(),
68
69 std::make_shared<OpenAIPMapProvider>(),
70
71 std::make_shared<CustomURLMapProvider>(),
72
73 std::make_shared<CopernicusElevationProvider>()
74};
75
76QString UrlFactory::getImageFormat(int qtMapId, QByteArrayView image)
77{
78 const SharedMapProvider provider = getMapProviderFromQtMapId(qtMapId);
79 if (provider) {
80 return provider->getImageFormat(image);
81 }
82
83 return QString("");
84}
85
86QString UrlFactory::getImageFormat(QStringView type, QByteArrayView image)
87{
89 if (provider) {
90 return provider->getImageFormat(image);
91 }
92
93 return QString("");
94}
95
96QUrl UrlFactory::getTileURL(int qtMapId, int x, int y, int zoom)
97{
98 const SharedMapProvider provider = getMapProviderFromQtMapId(qtMapId);
99 if (provider) {
100 return provider->getTileURL(x, y, zoom);
101 }
102
103 return QUrl();
104}
105
106QUrl UrlFactory::getTileURL(QStringView type, int x, int y, int zoom)
107{
109 if (provider) {
110 return provider->getTileURL(x, y, zoom);
111 }
112
113 return QUrl();
114}
115
116quint32 UrlFactory::averageSizeForType(QStringView type)
117{
119 if (provider) {
120 return provider->getAverageSize();
121 }
122
124}
125
126bool UrlFactory::isElevation(int qtMapId)
127{
128 const SharedMapProvider provider = getMapProviderFromQtMapId(qtMapId);
129 if (provider) {
130 return provider->isElevationProvider();
131 }
132
133 return false;
134}
135
136int UrlFactory::long2tileX(QStringView mapType, double lon, int z)
137{
138 const SharedMapProvider provider = getMapProviderFromProviderType(mapType);
139 if (provider) {
140 return provider->long2tileX(lon, z);
141 }
142
143 return 0;
144}
145
146int UrlFactory::lat2tileY(QStringView mapType, double lat, int z)
147{
148 const SharedMapProvider provider = getMapProviderFromProviderType(mapType);
149 if (provider) {
150 return provider->lat2tileY(lat, z);
151 }
152
153 return 0;
154}
155
156QGCTileSet UrlFactory::getTileCount(int zoom, double topleftLon, double topleftLat, double bottomRightLon, double bottomRightLat, QStringView mapType)
157{
158 const SharedMapProvider provider = getMapProviderFromProviderType(mapType);
159 if (provider) {
160 // TODO: zoom = qBound(QGeoCameraCapabilities.minimumZoomLevel(), zoom, QGeoCameraCapabilities.maximumZoomLevel());
161 zoom = qBound(1, zoom, QGC_MAX_MAP_ZOOM);
162 return provider->getTileCount(zoom, topleftLon, topleftLat, bottomRightLon, bottomRightLat);
163 }
164
165 return QGCTileSet();
166}
167
169{
170 if (qtMapId == -1) {
171 return QString();
172 }
173
174 for (const SharedMapProvider &provider : _providers) {
175 if (provider->getMapId() == qtMapId) {
176 return provider->getMapName();
177 }
178 }
179
180 qCWarning(QGCMapUrlEngineLog) << "map id not found:" << qtMapId;
181 return QString();
182}
183
185{
186 if (qtMapId == -1) {
187 return nullptr;
188 }
189
190 for (const SharedMapProvider &provider : _providers) {
191 if (provider->getMapId() == qtMapId) {
192 return provider;
193 }
194 }
195
196 qCWarning(QGCMapUrlEngineLog) << "provider not found from id:" << qtMapId;
197 return nullptr;
198}
199
201{
202 if (type.isEmpty()) {
203 return nullptr;
204 }
205
206 for (const SharedMapProvider &provider : _providers) {
207 if (provider->getMapName() == type) {
208 return provider;
209 }
210 }
211
212 qCWarning(QGCMapUrlEngineLog) << "type not found:" << type;
213 return nullptr;
214}
215
217{
218 if (type.isEmpty()) {
219 return -1;
220 }
221
222 for (const SharedMapProvider &provider : _providers) {
223 if (provider->getMapName() == type) {
224 return provider->getMapId();
225 }
226 }
227
228 qCWarning(QGCMapUrlEngineLog) << "type not found:" << type;
229 return -1;
230}
231
233{
234 QStringList types;
235 for (const SharedMapProvider &provider : _providers) {
236 if (provider->isElevationProvider()) {
237 types.append(provider->getMapName());
238 }
239 }
240
241 return types;
242}
243
245{
246 QStringList types;
247 for (const SharedMapProvider &provider : _providers) {
248 types.append(provider->getMapName());
249 }
250
251 return types;
252}
253
255{
256 for (const SharedMapProvider &provider : _providers) {
257 const QString mapName = provider->getMapName();
258 if (hashFromProviderType(mapName) == hash) {
259 return mapName;
260 }
261 }
262
263 qCWarning(QGCMapUrlEngineLog) << "provider not found from hash:" << hash;
264 return QString("");
265}
266
268{
269 for (const SharedMapProvider &provider : _providers) {
270 if (provider->getMapName() == type) {
271 return provider->getMapId();
272 }
273 }
274
275 qCWarning(QGCMapUrlEngineLog) << "provider not found for type:" << type;
276 return -1;
277}
278
279QString UrlFactory::tileHashToType(QStringView tileHash)
280{
281 const int providerHash = tileHash.mid(0,10).toInt();
282 return providerTypeFromHash(providerHash);
283}
284
285QString UrlFactory::getTileHash(QStringView type, int x, int y, int z)
286{
287 const int hash = hashFromProviderType(type);
288 return QString::asprintf("%010d%08d%08d%03d", hash, x, y, z);
289}
static constexpr const quint32 QGC_AVERAGE_TILE_SIZE
Definition MapProvider.h:10
#define QGC_MAX_MAP_ZOOM
Definition MapProvider.h:9
#define QGC_LOGGING_CATEGORY(name, categoryStr)
std::shared_ptr< const MapProvider > SharedMapProvider
static QUrl getTileURL(QStringView type, int x, int y, int zoom)
static QString getTileHash(QStringView type, int x, int y, int z)
static QStringList getProviderTypes()
static QGCTileSet getTileCount(int zoom, double topleftLon, double topleftLat, double bottomRightLon, double bottomRightLat, QStringView mapType)
static bool isElevation(int qtMapId)
static QString getProviderTypeFromQtMapId(int qtMapId)
static QString getImageFormat(QStringView type, QByteArrayView image)
static int lat2tileY(QStringView mapType, double lat, int z)
static QStringList getElevationProviderTypes()
static int hashFromProviderType(QStringView type)
static QString tileHashToType(QStringView tileHash)
static int long2tileX(QStringView mapType, double lon, int z)
static QString providerTypeFromHash(int hash)
static quint32 averageSizeForType(QStringView type)
static int getQtMapIdFromProviderType(QStringView type)
static std::shared_ptr< const MapProvider > getMapProviderFromProviderType(QStringView type)
static std::shared_ptr< const MapProvider > getMapProviderFromQtMapId(int qtMapId)