Commit 4eedf9d5 authored by Gus Grubba's avatar Gus Grubba

Separate terrain from tile maps within cached tile request system.

parent d7a73b51
...@@ -123,23 +123,23 @@ QGeoTiledMapReplyQGC::networkReplyFinished() ...@@ -123,23 +123,23 @@ QGeoTiledMapReplyQGC::networkReplyFinished()
} }
QByteArray a = _reply->readAll(); QByteArray a = _reply->readAll();
QString format = getQGCMapEngine()->urlFactory()->getImageFormat((UrlFactory::MapType)tileSpec().mapId(), a); QString format = getQGCMapEngine()->urlFactory()->getImageFormat((UrlFactory::MapType)tileSpec().mapId(), a);
//-- Test for a specialized, elevation data (not map tile)
// convert "a" to binary in case we have elevation data
if ((UrlFactory::MapType)tileSpec().mapId() == UrlFactory::MapType::AirmapElevation) { if ((UrlFactory::MapType)tileSpec().mapId() == UrlFactory::MapType::AirmapElevation) {
a = TerrainTile::serialize(a); a = TerrainTile::serialize(a);
if (a.isEmpty()) { //-- Cache it if valid
emit aborted(); if(!a.isEmpty()) {
return; getQGCMapEngine()->cacheTile(UrlFactory::MapType::AirmapElevation, tileSpec().x(), tileSpec().y(), tileSpec().zoom(), a, format);
} }
emit terrainDone(a, QNetworkReply::NoError);
} } else {
setMapImageData(a); //-- This is a map tile. Process and ache it if valid.
if(!format.isEmpty()) { setMapImageData(a);
setMapImageFormat(format); if(!format.isEmpty()) {
getQGCMapEngine()->cacheTile((UrlFactory::MapType)tileSpec().mapId(), tileSpec().x(), tileSpec().y(), tileSpec().zoom(), a, format); setMapImageFormat(format);
getQGCMapEngine()->cacheTile((UrlFactory::MapType)tileSpec().mapId(), tileSpec().x(), tileSpec().y(), tileSpec().zoom(), a, format);
}
setFinished(true);
} }
setFinished(true);
_clearReply(); _clearReply();
} }
...@@ -151,11 +151,17 @@ QGeoTiledMapReplyQGC::networkReplyError(QNetworkReply::NetworkError error) ...@@ -151,11 +151,17 @@ QGeoTiledMapReplyQGC::networkReplyError(QNetworkReply::NetworkError error)
if (!_reply) { if (!_reply) {
return; return;
} }
if (error != QNetworkReply::OperationCanceledError) { //-- Test for a specialized, elevation data (not map tile)
qWarning() << "Fetch tile error:" << _reply->errorString(); if ((UrlFactory::MapType)tileSpec().mapId() == UrlFactory::MapType::AirmapElevation) {
setError(QGeoTiledMapReply::CommunicationError, _reply->errorString()); emit terrainDone(QByteArray(), error);
} else {
//-- Regular map tile
if (error != QNetworkReply::OperationCanceledError) {
qWarning() << "Fetch tile error:" << _reply->errorString();
setError(QGeoTiledMapReply::CommunicationError, _reply->errorString());
}
setFinished(true);
} }
setFinished(true);
_clearReply(); _clearReply();
} }
...@@ -164,8 +170,12 @@ void ...@@ -164,8 +170,12 @@ void
QGeoTiledMapReplyQGC::cacheError(QGCMapTask::TaskType type, QString /*errorString*/) QGeoTiledMapReplyQGC::cacheError(QGCMapTask::TaskType type, QString /*errorString*/)
{ {
if(!getQGCMapEngine()->isInternetActive()) { if(!getQGCMapEngine()->isInternetActive()) {
setError(QGeoTiledMapReply::CommunicationError, "Network not available"); if ((UrlFactory::MapType)tileSpec().mapId() == UrlFactory::MapType::AirmapElevation) {
setFinished(true); emit terrainDone(QByteArray(), QNetworkReply::NetworkSessionFailedError);
} else {
setError(QGeoTiledMapReply::CommunicationError, "Network not available");
setFinished(true);
}
} else { } else {
if(type != QGCMapTask::taskFetchTile) { if(type != QGCMapTask::taskFetchTile) {
qWarning() << "QGeoTiledMapReplyQGC::cacheError() for wrong task"; qWarning() << "QGeoTiledMapReplyQGC::cacheError() for wrong task";
...@@ -196,10 +206,16 @@ QGeoTiledMapReplyQGC::cacheError(QGCMapTask::TaskType type, QString /*errorStrin ...@@ -196,10 +206,16 @@ QGeoTiledMapReplyQGC::cacheError(QGCMapTask::TaskType type, QString /*errorStrin
void void
QGeoTiledMapReplyQGC::cacheReply(QGCCacheTile* tile) QGeoTiledMapReplyQGC::cacheReply(QGCCacheTile* tile)
{ {
setMapImageData(tile->img()); //-- Test for a specialized, elevation data (not map tile)
setMapImageFormat(tile->format()); if ((UrlFactory::MapType)tileSpec().mapId() == UrlFactory::MapType::AirmapElevation) {
setFinished(true); emit terrainDone(tile->img(), QNetworkReply::NoError);
setCached(true); } else {
//-- Regular map tile
setMapImageData(tile->img());
setMapImageFormat(tile->format());
setFinished(true);
setCached(true);
}
tile->deleteLater(); tile->deleteLater();
} }
...@@ -210,5 +226,8 @@ QGeoTiledMapReplyQGC::timeout() ...@@ -210,5 +226,8 @@ QGeoTiledMapReplyQGC::timeout()
if(_reply) { if(_reply) {
_reply->abort(); _reply->abort();
} }
if ((UrlFactory::MapType)tileSpec().mapId() == UrlFactory::MapType::AirmapElevation) {
emit terrainDone(QByteArray(), QNetworkReply::TimeoutError);
}
emit aborted(); emit aborted();
} }
...@@ -61,6 +61,9 @@ public: ...@@ -61,6 +61,9 @@ public:
~QGeoTiledMapReplyQGC(); ~QGeoTiledMapReplyQGC();
void abort(); void abort();
signals:
void terrainDone (QByteArray responseBytes, QNetworkReply::NetworkError error);
private slots: private slots:
void networkReplyFinished (); void networkReplyFinished ();
void networkReplyError (QNetworkReply::NetworkError error); void networkReplyError (QNetworkReply::NetworkError error);
......
...@@ -374,8 +374,7 @@ bool TerrainTileManager::_getAltitudesForCoordinates(const QList<QGeoCoordinate> ...@@ -374,8 +374,7 @@ bool TerrainTileManager::_getAltitudesForCoordinates(const QList<QGeoCoordinate>
spec.setZoom(1); spec.setZoom(1);
spec.setMapId(UrlFactory::AirmapElevation); spec.setMapId(UrlFactory::AirmapElevation);
QGeoTiledMapReplyQGC* reply = new QGeoTiledMapReplyQGC(&_networkManager, request, spec); QGeoTiledMapReplyQGC* reply = new QGeoTiledMapReplyQGC(&_networkManager, request, spec);
connect(reply, &QGeoTiledMapReplyQGC::finished, this, &TerrainTileManager::_fetchedTile); connect(reply, &QGeoTiledMapReplyQGC::terrainDone, this, &TerrainTileManager::_terrainDone);
connect(reply, &QGeoTiledMapReplyQGC::aborted, this, &TerrainTileManager::_fetchedTile);
_state = State::Downloading; _state = State::Downloading;
} }
_tilesMutex.unlock(); _tilesMutex.unlock();
...@@ -406,7 +405,7 @@ void TerrainTileManager::_tileFailed(void) ...@@ -406,7 +405,7 @@ void TerrainTileManager::_tileFailed(void)
_requestQueue.clear(); _requestQueue.clear();
} }
void TerrainTileManager::_fetchedTile() void TerrainTileManager::_terrainDone(QByteArray responseBytes, QNetworkReply::NetworkError error)
{ {
QGeoTiledMapReplyQGC* reply = qobject_cast<QGeoTiledMapReplyQGC*>(QObject::sender()); QGeoTiledMapReplyQGC* reply = qobject_cast<QGeoTiledMapReplyQGC*>(QObject::sender());
_state = State::Idle; _state = State::Idle;
...@@ -421,26 +420,19 @@ void TerrainTileManager::_fetchedTile() ...@@ -421,26 +420,19 @@ void TerrainTileManager::_fetchedTile()
QString hash = QGCMapEngine::getTileHash(UrlFactory::AirmapElevation, spec.x(), spec.y(), spec.zoom()); QString hash = QGCMapEngine::getTileHash(UrlFactory::AirmapElevation, spec.x(), spec.y(), spec.zoom());
// handle potential errors // handle potential errors
if (reply->error() != QGeoTiledMapReply::NoError) { if (error != QNetworkReply::NoError) {
if (reply->error() == QGeoTiledMapReply::CommunicationError) { qCDebug(TerrainQueryLog) << "Elevation tile fetching returned error (" << error << ")";
qCDebug(TerrainQueryLog) << "Elevation tile fetching returned communication error. " << reply->errorString();
} else {
qCDebug(TerrainQueryLog) << "Elevation tile fetching returned error. " << reply->errorString();
}
_tileFailed(); _tileFailed();
reply->deleteLater(); reply->deleteLater();
return; return;
} }
if (!reply->isFinished()) { if (responseBytes.isEmpty()) {
qCDebug(TerrainQueryLog) << "Error in fetching elevation tile. Not finished. " << reply->errorString(); qCDebug(TerrainQueryLog) << "Error in fetching elevation tile. Empty response.";
_tileFailed(); _tileFailed();
reply->deleteLater(); reply->deleteLater();
return; return;
} }
// parse received data and insert into hash table
QByteArray responseBytes = reply->mapImageData();
qWarning() << "Received some bytes of terrain data: " << responseBytes.size(); qWarning() << "Received some bytes of terrain data: " << responseBytes.size();
TerrainTile* terrainTile = new TerrainTile(responseBytes); TerrainTile* terrainTile = new TerrainTile(responseBytes);
......
...@@ -62,20 +62,20 @@ public: ...@@ -62,20 +62,20 @@ public:
TerrainAirMapQuery(QObject* parent = NULL); TerrainAirMapQuery(QObject* parent = NULL);
// Overrides from TerrainQueryInterface // Overrides from TerrainQueryInterface
void requestCoordinateHeights(const QList<QGeoCoordinate>& coordinates) final; void requestCoordinateHeights (const QList<QGeoCoordinate>& coordinates) final;
void requestPathHeights(const QGeoCoordinate& fromCoord, const QGeoCoordinate& toCoord) final; void requestPathHeights (const QGeoCoordinate& fromCoord, const QGeoCoordinate& toCoord) final;
void requestCarpetHeights(const QGeoCoordinate& swCoord, const QGeoCoordinate& neCoord, bool statsOnly) final; void requestCarpetHeights (const QGeoCoordinate& swCoord, const QGeoCoordinate& neCoord, bool statsOnly) final;
private slots: private slots:
void _requestError(QNetworkReply::NetworkError code); void _requestError (QNetworkReply::NetworkError code);
void _requestFinished(void); void _requestFinished ();
private: private:
void _sendQuery (const QString& path, const QUrlQuery& urlQuery); void _sendQuery (const QString& path, const QUrlQuery& urlQuery);
void _requestFailed (void); void _requestFailed (void);
void _parseCoordinateData (const QJsonValue& coordinateJson); void _parseCoordinateData (const QJsonValue& coordinateJson);
void _parsePathData (const QJsonValue& pathJson); void _parsePathData (const QJsonValue& pathJson);
void _parseCarpetData (const QJsonValue& carpetJson); void _parseCarpetData (const QJsonValue& carpetJson);
enum QueryMode { enum QueryMode {
QueryModeCoordinates, QueryModeCoordinates,
...@@ -117,7 +117,7 @@ public: ...@@ -117,7 +117,7 @@ public:
void addPathQuery (TerrainOfflineAirMapQuery* terrainQueryInterface, const QGeoCoordinate& startPoint, const QGeoCoordinate& endPoint); void addPathQuery (TerrainOfflineAirMapQuery* terrainQueryInterface, const QGeoCoordinate& startPoint, const QGeoCoordinate& endPoint);
private slots: private slots:
void _fetchedTile (void); /// slot to handle fetched elevation tiles void _terrainDone (QByteArray responseBytes, QNetworkReply::NetworkError error);
private: private:
enum class State { enum class State {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment