From dd5229fa845bb505d67fceff24f0b75f0cd7ef8b Mon Sep 17 00:00:00 2001 From: Pierre TILAK Date: Thu, 19 Sep 2019 14:24:44 +1200 Subject: [PATCH] Remove Airmap from MapReplyQGC --- src/QtLocationPlugin/QGCMapUrlEngine.cpp | 24 +++++++----------------- src/QtLocationPlugin/QGCMapUrlEngine.h | 2 ++ src/QtLocationPlugin/QGeoMapReplyQGC.cpp | 17 ++++++++--------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/QtLocationPlugin/QGCMapUrlEngine.cpp b/src/QtLocationPlugin/QGCMapUrlEngine.cpp index a8b6869de..2b3cafbf5 100644 --- a/src/QtLocationPlugin/QGCMapUrlEngine.cpp +++ b/src/QtLocationPlugin/QGCMapUrlEngine.cpp @@ -146,7 +146,7 @@ QString UrlFactory::getTypeFromId(int id) { while (i.hasNext()) { i.next(); - if (abs(qHash(i.key())) == id) { + if ((int)(qHash(i.key())>>1) == id) { return i.key(); } } @@ -155,9 +155,9 @@ QString UrlFactory::getTypeFromId(int id) { } // Todo : qHash produce a uint bigger than max(int) -// There is still a low probability for abs to +// There is still a low probability for this to // generate similar hash for different types -int UrlFactory::getIdFromType(QString type) { return abs(qHash(type)); } +int UrlFactory::getIdFromType(QString type) { return (int)(qHash(type)>>1); } //----------------------------------------------------------------------------- int @@ -178,19 +178,9 @@ UrlFactory::lat2tileY(QString mapType, double lat, int z) QGCTileSet UrlFactory::getTileCount(int zoom, double topleftLon, double topleftLat, double bottomRightLon, double bottomRightLat, QString mapType) { - //QGCTileSet set; - //if(mapType != "Airmap Elevation"){ - // set.tileX0 = long2tileX(mapType, topleftLon, zoom); - // set.tileY0 = lat2tileY(mapType, topleftLat, zoom); - // set.tileX1 = long2tileX(mapType, bottomRightLon, zoom); - // set.tileY1 = lat2tileY(mapType, bottomRightLat, zoom); - //}else{ - // set.tileX0 = getQGCMapEngine()->urlFactory()->long2tileX(mapType, topleftLon, zoom); - // set.tileY0 = getQGCMapEngine()->urlFactory()->lat2tileY(mapType, bottomRightLat, zoom); - // set.tileX1 = getQGCMapEngine()->urlFactory()->long2tileX(mapType, bottomRightLon, zoom); - // set.tileY1 = getQGCMapEngine()->urlFactory()->lat2tileY(mapType, topleftLat, zoom); - //} - //set.tileCount = (static_cast(set.tileX1) - static_cast(set.tileX0) + 1) * (static_cast(set.tileY1) - static_cast(set.tileY0) + 1); - //set.tileSize = getQGCMapEngine()->urlFactory()->averageSizeForType(mapType) * set.tileCount; return _providersTable[mapType]->getTileCount(zoom, topleftLon, topleftLat, bottomRightLon, bottomRightLat); } + +bool UrlFactory::isElevation(int mapId){ + return _providersTable[getTypeFromId(mapId)]->_isElevationProvider(); +} diff --git a/src/QtLocationPlugin/QGCMapUrlEngine.h b/src/QtLocationPlugin/QGCMapUrlEngine.h index 2a0563be0..bd67c64a2 100644 --- a/src/QtLocationPlugin/QGCMapUrlEngine.h +++ b/src/QtLocationPlugin/QGCMapUrlEngine.h @@ -53,6 +53,8 @@ public: double bottomRightLon, double bottomRightLat, QString mapType); + bool isElevation(int mapId); + private: int _timeout; QHash _providersTable; diff --git a/src/QtLocationPlugin/QGeoMapReplyQGC.cpp b/src/QtLocationPlugin/QGeoMapReplyQGC.cpp index e6098b8fc..2468c2556 100644 --- a/src/QtLocationPlugin/QGeoMapReplyQGC.cpp +++ b/src/QtLocationPlugin/QGeoMapReplyQGC.cpp @@ -124,12 +124,14 @@ QGeoTiledMapReplyQGC::networkReplyFinished() QByteArray a = _reply->readAll(); QString format = getQGCMapEngine()->urlFactory()->getImageFormat(tileSpec().mapId(), a); //-- Test for a specialized, elevation data (not map tile) - int AirmapElevationId = getQGCMapEngine()->urlFactory()->getIdFromType("Airmap Elevation"); - if (tileSpec().mapId() == AirmapElevationId) { + if( getQGCMapEngine()->urlFactory()->isElevation(tileSpec().mapId())){ a = TerrainTile::serialize(a); //-- Cache it if valid if(!a.isEmpty()) { - getQGCMapEngine()->cacheTile("Airmap Elevation", tileSpec().x(), tileSpec().y(), tileSpec().zoom(), a, format); + getQGCMapEngine()->cacheTile( + getQGCMapEngine()->urlFactory()->getTypeFromId( + tileSpec().mapId()), + tileSpec().x(), tileSpec().y(), tileSpec().zoom(), a, format); } emit terrainDone(a, QNetworkReply::NoError); } else { @@ -153,8 +155,7 @@ QGeoTiledMapReplyQGC::networkReplyError(QNetworkReply::NetworkError error) return; } //-- Test for a specialized, elevation data (not map tile) - int AirmapElevationId = getQGCMapEngine()->urlFactory()->getIdFromType("Airmap Elevation"); - if (tileSpec().mapId() == AirmapElevationId) { + if( getQGCMapEngine()->urlFactory()->isElevation(tileSpec().mapId())){ emit terrainDone(QByteArray(), error); } else { //-- Regular map tile @@ -172,8 +173,7 @@ void QGeoTiledMapReplyQGC::cacheError(QGCMapTask::TaskType type, QString /*errorString*/) { if(!getQGCMapEngine()->isInternetActive()) { - int AirmapElevationId = getQGCMapEngine()->urlFactory()->getIdFromType("Airmap Elevation"); - if (tileSpec().mapId() == AirmapElevationId) { + if( getQGCMapEngine()->urlFactory()->isElevation(tileSpec().mapId())){ emit terrainDone(QByteArray(), QNetworkReply::NetworkSessionFailedError); } else { setError(QGeoTiledMapReply::CommunicationError, "Network not available"); @@ -210,8 +210,7 @@ void QGeoTiledMapReplyQGC::cacheReply(QGCCacheTile* tile) { //-- Test for a specialized, elevation data (not map tile) - int AirmapElevationId = getQGCMapEngine()->urlFactory()->getIdFromType("Airmap Elevation"); - if (tileSpec().mapId() == AirmapElevationId) { + if( getQGCMapEngine()->urlFactory()->isElevation(tileSpec().mapId())){ emit terrainDone(tile->img(), QNetworkReply::NoError); } else { //-- Regular map tile -- 2.22.0