Skip to content

Commit aac6b94

Browse files
authored
Merge pull request #2 from Pix4D/nuri/RAG-4829-mapbox-url
RAG-4829: Update mapbox URL
2 parents 1d25752 + 54b6127 commit aac6b94

File tree

5 files changed

+65
-39
lines changed

5 files changed

+65
-39
lines changed

src/GeoFileTileCache.cpp

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
GeoFileTileCache::GeoFileTileCache(const QList<QGeoMapType>& mapTypes,
77
int scaleFactor,
8+
bool enableLogging,
89
const QString& directory,
910
QObject* parent)
1011
: QGeoFileTileCache(directory, parent)
12+
, m_enableLogging(enableLogging)
1113
, m_hasCacheDirectory(!directory.isEmpty())
1214
, m_mapTypes(mapTypes)
1315
{
@@ -58,72 +60,90 @@ QGeoTileSpec GeoFileTileCache::filenameToTileSpec(const QString& filename) const
5860
// @See QGeoFileTileCacheMapBox for more information for this function
5961
// General scheme is: plugin_name - map_type - zoom - x - y - @scale.png
6062
// For now the cached tiles names look like this:
61-
// basemap_pix4d_100-mapbox.streets-satellite-[email protected] or
62-
// basemap_pix4d_100-mapbox.satellite[email protected]
63+
// basemap_pix4d_100-ck8zzfxb30vwp1jo04yktjtbg-[email protected] or
64+
// basemap_pix4d_100-ck8zz9gpq0vty1ip30bji3b5a[email protected]
6365
// basemap_pix4d_100 = plugin name
64-
// mapbox.streets-satellite / mapbox.satellite = map type
66+
// ck8zzfxb30vwp1jo04yktjtbg = streets-satellite type map
67+
// ck8zz9gpq0vty1ip30bji3b5a = street type map
6568
// 13 = zoom
6669
// 4401-2685 = x, y
6770

6871
if (!m_hasCacheDirectory)
6972
{
73+
if (m_enableLogging)
74+
{
75+
qWarning() << "GeoFileTileCache: No cache directory.";
76+
}
7077
return QGeoTileSpec();
7178
}
7279

7380
const QStringList parts = filename.split('.');
74-
if (parts.length() != 3) // 3 because the map name has always a dot in it.
81+
if (parts.length() != 2) // 2 because the map name has always a dot in it.
7582
{
83+
if (m_enableLogging)
84+
{
85+
qWarning() << "GeoFileTileCache: This file doesn't have a file extension.";
86+
}
7687
return QGeoTileSpec();
7788
}
7889

79-
// name = mapbox_pix4d_100-mapbox.streets-satellite-13-4401-2685-@2x (no extension)
80-
const QString name = parts.at(0) + "." + parts.at(1);
90+
// name = mapbox_pix4d_100-ck8zzfxb30vwp1jo04yktjtbg-13-4401-2685-@2x (no extension)
91+
const QString name = parts.at(0);
8192
const QStringList fields = name.split('-');
8293

8394
// must be at least 6 different fields
8495
if (fields.length() < 6)
8596
{
97+
if (m_enableLogging)
98+
{
99+
qWarning() << "GeoFileTileCache: The file name without extension doesn't have 6 different fields.";
100+
}
86101
return QGeoTileSpec();
87102
}
88103

89104
const int length = fields.length();
90105
const int scaleIdx = fields.last().indexOf("@");
91106
if (scaleIdx < 0 || fields.last().size() <= (scaleIdx + 2))
92107
{
108+
if (m_enableLogging)
109+
{
110+
qWarning() << "GeoFileTileCache: Scale is not last data in name.";
111+
}
93112
return QGeoTileSpec();
94113
}
95114

96115
int scaleFactor = fields.last()[scaleIdx + 1].digitValue();
97116
if (scaleFactor != m_scaleFactor)
98117
{
118+
if (m_enableLogging)
119+
{
120+
qWarning() << "GeoFileTileCache: The last fields doesn't have scale factor.";
121+
}
99122
return QGeoTileSpec();
100123
}
101124

102125
QList<int> numbers;
103-
int startIndex = 2;
104-
105-
// try to combine the fields from [1] and [2]. In case the map type
106-
// contains a '-' in it (e.g. mapbox.streets-satellite vs mapbox.satellite)
107-
QString pluginName = fields.at(1);
108-
if (m_mapNameToId.find(pluginName + "-" + fields.at(2)) != m_mapNameToId.end())
109-
{
110-
pluginName += "-" + fields.at(2);
111-
startIndex = 3;
112-
}
113-
114-
for (int i = startIndex; i < length - 1; ++i) // skipping -@_X
126+
for (int i = 2; i < length - 1; ++i) // skipping -@_X
115127
{
116128
bool ok = false;
117129
const int value = fields.at(i).toInt(&ok);
118130
if (!ok)
119131
{
132+
if (m_enableLogging)
133+
{
134+
qWarning() << "GeoFileTileCache: The value of zoom/x/y must be integer.";
135+
}
120136
return QGeoTileSpec();
121137
}
122138
numbers.append(value);
123139
}
124140

125141
if (numbers.length() < 3)
126142
{
143+
if (m_enableLogging)
144+
{
145+
qWarning() << "GeoFileTileCache: The cache file must have zoom/x/y value.";
146+
}
127147
return QGeoTileSpec();
128148
}
129149

@@ -134,5 +154,5 @@ QGeoTileSpec GeoFileTileCache::filenameToTileSpec(const QString& filename) const
134154
}
135155

136156
return QGeoTileSpec(
137-
fields.at(0), m_mapNameToId[pluginName], numbers.at(0), numbers.at(1), numbers.at(2), numbers.at(3));
138-
}
157+
fields.at(0), m_mapNameToId[fields.at(1)], numbers.at(0), numbers.at(1), numbers.at(2), numbers.at(3));
158+
}

src/GeoFileTileCache.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ class GeoFileTileCache : public QGeoFileTileCache
88
Q_OBJECT
99

1010
public:
11-
GeoFileTileCache(const QList<QGeoMapType>& mapTypes, int scaleFactor, const QString& directory = QString(), QObject* parent = nullptr);
11+
GeoFileTileCache(const QList<QGeoMapType>& mapTypes, int scaleFactor, bool enableLogging, const QString& directory = QString(), QObject* parent = nullptr);
1212

1313
protected:
1414
QString tileSpecToFilename(const QGeoTileSpec& spec, const QString& format, const QString& directory) const override;
1515
QGeoTileSpec filenameToTileSpec(const QString& filename) const override;
1616

17+
bool m_enableLogging{false};
1718
bool m_hasCacheDirectory{false};
1819
QList<QGeoMapType> m_mapTypes;
1920
QMap<QString, int> m_mapNameToId;
2021
int m_scaleFactor{0};
21-
};
22+
};

src/GeoTileFetcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ QGeoTiledMapReply* GeoTileFetcher::getTileImage(const QGeoTileSpec& spec)
154154
{
155155
request.setUrl(
156156
QUrl(QStringLiteral("https://api.mapbox.com/styles/v1/cloudpix4d/")
157-
+ m_mapIds[(spec.mapId() > m_mapIds.size()) ? 0 : spec.mapId() - 1]
157+
+ ((spec.mapId() > m_mapIds.size()) ? PIX4D_STREET : m_mapIds[spec.mapId() - 1])
158158
+ QLatin1String("/tiles/256/")
159159
+ QString::number(spec.zoom())
160160
+ QLatin1Char('/')

src/GeoTileFetcher.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class GeoTileFetcher : public QGeoTileFetcher
2020
private:
2121
QGeoTiledMapReply* getTileImage(const QGeoTileSpec& spec);
2222

23+
public:
24+
// The list of map style ids
25+
static constexpr const char* PIX4D_STREET = "ck8zz9gpq0vty1ip30bji3b5a";
26+
static constexpr const char* PIX4D_STREETS_SATELLITE = "ck8zzfxb30vwp1jo04yktjtbg";
27+
2328
private:
2429
QNetworkAccessManager* m_networkManager{nullptr};
2530
QByteArray m_userAgent;

src/GeoTiledMappingManagerEngine.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,22 @@ GeoTiledMappingManagerEngine::GeoTiledMappingManagerEngine(const QVariantMap& pa
7474
QVector<QString> mapIds;
7575
if (usingMapBox)
7676
{
77-
mapTypes << QGeoMapType(QGeoMapType::HybridMap,
78-
QStringLiteral("ck8zzfxb30vwp1jo04yktjtbg"),
79-
QStringLiteral("Streets Satellite"),
80-
false,
81-
false,
82-
mapTypes.size() + 1,
83-
pluginName,
84-
cameraCaps);
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);
8585
mapTypes << QGeoMapType(QGeoMapType::StreetMap,
86-
QStringLiteral("ck8zz9gpq0vty1ip30bji3b5a"),
87-
QStringLiteral("Street"),
88-
false,
89-
false,
90-
mapTypes.size() + 1,
91-
pluginName,
92-
cameraCaps);
86+
GeoTileFetcher::PIX4D_STREET,
87+
QStringLiteral("Street"),
88+
false,
89+
false,
90+
mapTypes.size() + 1,
91+
pluginName,
92+
cameraCaps);
9393

9494
for (const auto& type : mapTypes)
9595
{
@@ -130,7 +130,7 @@ GeoTiledMappingManagerEngine::GeoTiledMappingManagerEngine(const QVariantMap& pa
130130
cacheDirectory = QAbstractGeoTileCache::baseLocationCacheDirectory() + QLatin1String(pluginName);
131131
}
132132

133-
auto tileCache = new GeoFileTileCache(mapTypes, scaleFactor, cacheDirectory);
133+
auto tileCache = new GeoFileTileCache(mapTypes, scaleFactor, enableLogging, cacheDirectory);
134134
tileCache->setCostStrategyDisk(QGeoFileTileCache::Unitary);
135135
tileCache->setCostStrategyMemory(QGeoFileTileCache::ByteSize);
136136
tileCache->setCostStrategyTexture(QGeoFileTileCache::ByteSize);

0 commit comments

Comments
 (0)