Skip to content

Commit

Permalink
Move serializeFromAirMapJson to map providers, from QGCMapTileSet:
Browse files Browse the repository at this point in the history
We used to have in QGCMapTileSet::_networkReplyFinished() this
serializeFromAirMapJson hardcoded to the airmap elevation string.

Instead we added functions in urlFactory and map providers so we
can understand from the map provider hash if such map provider
needs its tiles to be serialized, and if so, we call the same
provider to perform such serialization.

This way the base MapProvider class returns by default that no
serialization is needed, and the method to serialize just returns
the same QByteArray ( we should never use this, it is just a sanity check )

Then in Airmap elevation map provider we override this, and we
implement our own serialization method, which calls the
TerrainTile method that was originally called from
QGCMapTileSet.

This way it is also more obvious when developing support for new
elevation map providers, as the relevant methods are contained
within the elevation map providers definition files
  • Loading branch information
Davidsastresas committed Jun 19, 2023
1 parent fe3433a commit 43a7098
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/QtLocationPlugin/ElevationMapProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ QGCTileSet AirmapElevationProvider::getTileCount(const int zoom, const double to

return set;
}

QByteArray AirmapElevationProvider::serializeTile(QByteArray image) {
return TerrainTile::serializeFromAirMapJson(image);
}
5 changes: 5 additions & 0 deletions src/QtLocationPlugin/ElevationMapProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class AirmapElevationProvider : public ElevationProvider {
const double topleftLat, const double bottomRightLon,
const double bottomRightLat) const override;

// Airmap needs to serialize the tiles, because they are received in json format. This way we can work with
// them in the map tiles database
bool serializeTilesNeeded() override { return true; }
QByteArray serializeTile(QByteArray image) override;

protected:
QString _getURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager) override;
};
Expand Down
3 changes: 3 additions & 0 deletions src/QtLocationPlugin/MapProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class MapProvider : public QObject {
const double topleftLat, const double bottomRightLon,
const double bottomRightLat) const;

virtual bool serializeTilesNeeded() { return false; }
virtual QByteArray serializeTile(QByteArray image) { return image; }

protected:
QString _tileXYToQuadKey(const int tileX, const int tileY, const int levelOfDetail) const;
int _getServerNum(const int x, const int y, const int max) const;
Expand Down
5 changes: 3 additions & 2 deletions src/QtLocationPlugin/QGCMapTileSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ QGCCachedTileSet::_networkReplyFinished()
qCDebug(QGCCachedTileSetLog) << "Tile fetched" << hash;
QByteArray image = reply->readAll();
QString type = getQGCMapEngine()->hashToType(hash);
if (type == "Airmap Elevation" ) {
image = TerrainTile::serializeFromAirMapJson(image);
// Some providers need the images to be serialized because the response is not directly a image based tile
if (getQGCMapEngine()->urlFactory()->needsSerializingTiles(type)) {
image = getQGCMapEngine()->urlFactory()->serializeTileForId(image, type);
}
QString format = getQGCMapEngine()->urlFactory()->getImageFormat(type, image);
if(!format.isEmpty()) {
Expand Down
12 changes: 12 additions & 0 deletions src/QtLocationPlugin/QGCMapUrlEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,15 @@ UrlFactory::getTileCount(int zoom, double topleftLon, double topleftLat, double
bool UrlFactory::isElevation(int mapId){
return _providersTable[getTypeFromId(mapId)]->_isElevationProvider();
}

bool UrlFactory::isElevation(QString mapType){
return _providersTable[mapType]->_isElevationProvider();
}

bool UrlFactory::needsSerializingTiles(QString mapType){
return _providersTable[mapType]->serializeTilesNeeded();
}

QByteArray UrlFactory::serializeTileForId(QByteArray image, QString mapType){
return _providersTable[mapType]->serializeTile(image);
}
3 changes: 3 additions & 0 deletions src/QtLocationPlugin/QGCMapUrlEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ class UrlFactory : public QObject {
double bottomRightLon, double bottomRightLat,
QString mapType);

bool isElevation(QString mapType);
bool isElevation(int mapId);
bool needsSerializingTiles(QString mapType);
QByteArray serializeTileForId(QByteArray image, QString mapType);

private:
int _timeout;
Expand Down

0 comments on commit 43a7098

Please sign in to comment.