Skip to content

Commit 467628d

Browse files
Merge pull request #4 from Pix4D/RAG-5895-add-custom-maptype
Make custom basemap option of of the map types
2 parents aac6b94 + cfa3d3f commit 467628d

File tree

6 files changed

+81
-34
lines changed

6 files changed

+81
-34
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
### Changed
13+
14+
### Removed
15+
16+
17+
## QtBasemapPlugin 1.1.0-1
18+
19+
### Added
20+
- new "Custom"-MapType option which fetches map tiles from a custom url. When [Map QML Type](https://doc.qt.io/qt-5/qml-qtlocation-map.html) is used,
21+
the new map type can be chosen as [activeMapType](https://doc.qt.io/qt-5/qml-qtlocation-map.html#activeMapType-prop).
22+
23+
### Changed
24+
- if [plugin](https://doc.qt.io/qt-5/qml-qtlocation-plugin.html) is instantiated with custom url parameter, the switch between Satellite, Street (provided by mapbox)
25+
and Custom tiles (provided via custom basemap url) can be done without plugin [reinstantiation](https://doc.qt.io/qt-5/qml-qtlocation-map.html#plugin-prop)
26+

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class QtBasemapPluginConan(ConanFile):
66
name = 'QtBasemapPlugin'
7-
version = '1.0.1-4'
7+
version = '1.1.0-1'
88
license = 'LGPL3'
99
url = 'http://code.qt.io/cgit/qt/qtlocation.git/tree/src/plugins/geoservices/mapbox?h=5.10'
1010
description = 'Qt GeoServices plugin for basemaps including MapBox'

src/GeoFileTileCache.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ GeoFileTileCache::GeoFileTileCache(const QList<QGeoMapType>& mapTypes,
1616
m_scaleFactor = qBound(1, scaleFactor, 2);
1717
for (int i = 0; i < mapTypes.size(); i++)
1818
{
19-
m_mapNameToId.insert(mapTypes[i].name(), i + 1);
19+
m_mapNameToId.insert(mapTypes[i].name(), i);
2020
}
2121
}
2222

@@ -32,7 +32,7 @@ QString GeoFileTileCache::tileSpecToFilename(const QGeoTileSpec& spec,
3232
QString filename = spec.plugin();
3333

3434
filename += QLatin1String("-");
35-
filename += m_mapTypes[spec.mapId() - 1].name();
35+
filename += m_mapTypes[spec.mapId()].name();
3636
filename += QLatin1String("-");
3737
filename += QString::number(spec.zoom());
3838
filename += QLatin1String("-");

src/GeoTileFetcher.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,13 @@ QGeoTiledMapReply* GeoTileFetcher::getTileImage(const QGeoTileSpec& spec)
150150
request.setRawHeader("User-Agent", m_userAgent);
151151
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
152152

153-
if (m_customBasemapUrl.isEmpty())
153+
const bool isCustomBasemapRequest = (spec.mapId() < m_mapIds.size()) && !m_customBasemapUrl.isEmpty() && (m_mapIds[spec.mapId()] == PIX4D_CUSTOM);
154+
155+
QUrl tileUrl;
156+
if (!isCustomBasemapRequest)
154157
{
155-
request.setUrl(
156-
QUrl(QStringLiteral("https://api.mapbox.com/styles/v1/cloudpix4d/")
157-
+ ((spec.mapId() > m_mapIds.size()) ? PIX4D_STREET : m_mapIds[spec.mapId() - 1])
158+
tileUrl = QUrl(QStringLiteral("https://api.mapbox.com/styles/v1/cloudpix4d/")
159+
+ ((spec.mapId() > m_mapIds.size()) ? PIX4D_STREET : m_mapIds[spec.mapId()])
158160
+ QLatin1String("/tiles/256/")
159161
+ QString::number(spec.zoom())
160162
+ QLatin1Char('/')
@@ -164,7 +166,7 @@ QGeoTiledMapReply* GeoTileFetcher::getTileImage(const QGeoTileSpec& spec)
164166
+ ((m_scaleFactor > 1) ? (QLatin1Char('@') + QString::number(m_scaleFactor) + QLatin1Char('x')) : QString())
165167
+ QLatin1Char('?')
166168
+ QStringLiteral("access_token=")
167-
+ m_accessToken));
169+
+ m_accessToken);
168170
}
169171
else
170172
{
@@ -260,8 +262,10 @@ QGeoTiledMapReply* GeoTileFetcher::getTileImage(const QGeoTileSpec& spec)
260262
qInfo() << "Basemap tile requested" << urlDetails;
261263
}
262264

263-
request.setUrl(QUrl(basemapUrl));
265+
tileUrl = QUrl(basemapUrl);
264266
}
265267

268+
request.setUrl(tileUrl);
269+
266270
return new GeoMapReply(m_networkManager->get(request), spec, m_replyFormat, m_enableLogging);
267271
}

src/GeoTileFetcher.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ class GeoTileFetcher : public QGeoTileFetcher
2121
QGeoTiledMapReply* getTileImage(const QGeoTileSpec& spec);
2222

2323
public:
24-
// The list of map style ids
24+
// The list of map style names:
25+
// The two values below are part of url allowing to fetch corresponsing mapbox tiles
2526
static constexpr const char* PIX4D_STREET = "ck8zz9gpq0vty1ip30bji3b5a";
2627
static constexpr const char* PIX4D_STREETS_SATELLITE = "ck8zzfxb30vwp1jo04yktjtbg";
28+
// name for custom basemap tiles requests
29+
static constexpr const char* PIX4D_CUSTOM = "custom";
2730

2831
private:
2932
QNetworkAccessManager* m_networkManager{nullptr};

src/GeoTiledMappingManagerEngine.cpp

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,44 +63,58 @@ GeoTiledMappingManagerEngine::GeoTiledMappingManagerEngine(const QVariantMap& pa
6363
cameraCaps.setOverzoomEnabled(true);
6464
setCameraCapabilities(cameraCaps);
6565

66-
QString customBasemapUrl;
67-
getParameter(parameters, "custom_basemap_url", customBasemapUrl);
68-
const bool usingMapBox = customBasemapUrl.isEmpty();
69-
7066
setTileSize(QSize(256, 256));
7167
m_noMapTiles = getParameter(parameters, "no_map_tiles");
7268

7369
QList<QGeoMapType> mapTypes;
74-
QVector<QString> mapIds;
75-
if (usingMapBox)
76-
{
77-
mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay,
78-
GeoTileFetcher::PIX4D_STREETS_SATELLITE,
79-
QStringLiteral("Satellite"),
80-
false,
81-
false,
82-
mapTypes.size() + 1,
83-
pluginName,
84-
cameraCaps);
85-
mapTypes << QGeoMapType(QGeoMapType::StreetMap,
86-
GeoTileFetcher::PIX4D_STREET,
87-
QStringLiteral("Street"),
70+
mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay,
71+
GeoTileFetcher::PIX4D_STREETS_SATELLITE,
72+
QStringLiteral("Satellite"),
73+
false,
74+
false,
75+
mapTypes.size(),
76+
pluginName,
77+
cameraCaps);
78+
mapTypes << QGeoMapType(QGeoMapType::StreetMap,
79+
GeoTileFetcher::PIX4D_STREET,
80+
QStringLiteral("Street"),
81+
false,
82+
false,
83+
mapTypes.size(),
84+
pluginName,
85+
cameraCaps);
86+
87+
QString customBasemapUrl;
88+
getParameter(parameters, "custom_basemap_url", customBasemapUrl);
89+
if (!customBasemapUrl.isEmpty())
90+
mapTypes << QGeoMapType(QGeoMapType::CustomMap,
91+
"custom",
92+
QStringLiteral("Custom"),
8893
false,
8994
false,
90-
mapTypes.size() + 1,
95+
mapTypes.size(),
9196
pluginName,
9297
cameraCaps);
9398

94-
for (const auto& type : mapTypes)
99+
if (enableLogging)
100+
{
101+
qInfo() << "Plugin supports " << mapTypes.size() <<" map types:";
102+
for (const auto& t : qAsConst(mapTypes))
95103
{
96-
mapIds.push_back(type.name());
104+
qInfo() << t.description();
97105
}
98106
}
107+
99108
setSupportedMapTypes(mapTypes);
100109

101110
// Set up the tile fetcher
102111
const int scaleFactor = getParameter(parameters, "highdpi_tiles") ? 2 : 1;
103112
auto tileFetcher = new GeoTileFetcher(scaleFactor, enableLogging, customBasemapUrl, this);
113+
QVector<QString> mapIds;
114+
for (const auto& type : qAsConst(mapTypes))
115+
{
116+
mapIds.push_back(type.name());
117+
}
104118
tileFetcher->setMapIds(mapIds);
105119

106120
QString format;
@@ -121,11 +135,11 @@ GeoTiledMappingManagerEngine::GeoTiledMappingManagerEngine(const QVariantMap& pa
121135

122136
setTileFetcher(tileFetcher);
123137

124-
if (usingMapBox)
138+
if (customBasemapUrl.isEmpty())
125139
{
126140
// Set up the tile cache
127141
QString cacheDirectory;
128-
if (usingMapBox && !getParameter(parameters, "cache_directory", cacheDirectory))
142+
if (!getParameter(parameters, "cache_directory", cacheDirectory))
129143
{
130144
cacheDirectory = QAbstractGeoTileCache::baseLocationCacheDirectory() + QLatin1String(pluginName);
131145
}
@@ -157,7 +171,7 @@ QGeoMap* GeoTiledMappingManagerEngine::createMap()
157171
return m_noMapTiles ? new NoGeoTiledMap(this, 0) : new QGeoTiledMap(this, 0);
158172
}
159173

160-
QSGNode* NoGeoTiledMap::updateSceneGraph(QSGNode*, QQuickWindow* window)
174+
QSGNode* NoGeoTiledMap::updateSceneGraph(QSGNode*, QQuickWindow*)
161175
{
162176
return nullptr;
163177
}

0 commit comments

Comments
 (0)