diff --git a/src/QtLocationPlugin/ElevationMapProvider.cpp b/src/QtLocationPlugin/ElevationMapProvider.cpp index a2e38332991f48955e676d5ca4180b77e5c351af..03af2faece64aa7a900f89ea0970f838958e3446 100644 --- a/src/QtLocationPlugin/ElevationMapProvider.cpp +++ b/src/QtLocationPlugin/ElevationMapProvider.cpp @@ -37,3 +37,22 @@ AirmapElevationProvider::_getURL(int x, int y, int zoom, .arg(static_cast(x + 1) * srtm1TileSize - 180.0); } +QGCTileSet AirmapElevationProvider::getTileCount(int zoom, double topleftLon, + double topleftLat, + double bottomRightLon, + double bottomRightLat) { + QGCTileSet set; + set.tileX0 = long2tileX(topleftLon, zoom); + set.tileY0 = lat2tileY(bottomRightLat, zoom); + set.tileX1 = long2tileX(bottomRightLon, zoom); + set.tileY1 = lat2tileY(topleftLat, zoom); + + set.tileCount = (static_cast(set.tileX1) - + static_cast(set.tileX0) + 1) * + (static_cast(set.tileY1) - + static_cast(set.tileY0) + 1); + + set.tileSize = getAverageSize() * set.tileCount; + + return set; +} diff --git a/src/QtLocationPlugin/ElevationMapProvider.h b/src/QtLocationPlugin/ElevationMapProvider.h index 076dc51a076326c2ac262d6daf54cbd5c1159212..d23ad830ef779e6cf519e8015390c48559c8c17e 100644 --- a/src/QtLocationPlugin/ElevationMapProvider.h +++ b/src/QtLocationPlugin/ElevationMapProvider.h @@ -41,6 +41,9 @@ class AirmapElevationProvider : public ElevationProvider { int long2tileX(double lon, int z); int lat2tileY(double lat, int z); + QGCTileSet getTileCount(int zoom, double topleftLon, + double topleftLat, double bottomRightLon, + double bottomRightLat); protected: diff --git a/src/QtLocationPlugin/MapProvider.cpp b/src/QtLocationPlugin/MapProvider.cpp index 666008ea1d539d161d70b187dcfac96092ab2312..2d1a8fee3df6039f1a28c8455a31f3ce27905960 100644 --- a/src/QtLocationPlugin/MapProvider.cpp +++ b/src/QtLocationPlugin/MapProvider.cpp @@ -74,4 +74,22 @@ int MapProvider::lat2tileY(double lat, int z) { 2.0 * pow(2.0, z))); } -bool MapProvider::_isElevationProvider(){return false;} +bool MapProvider::_isElevationProvider() { return false; } + +QGCTileSet MapProvider::getTileCount(int zoom, double topleftLon, + double topleftLat, double bottomRightLon, + double bottomRightLat) { + QGCTileSet set; + set.tileX0 = long2tileX(topleftLon, zoom); + set.tileY0 = lat2tileY(topleftLat, zoom); + set.tileX1 = long2tileX(bottomRightLon, zoom); + set.tileY1 = lat2tileY(bottomRightLat, zoom); + + set.tileCount = (static_cast(set.tileX1) - + static_cast(set.tileX0) + 1) * + (static_cast(set.tileY1) - + static_cast(set.tileY0) + 1); + + set.tileSize = getAverageSize() * set.tileCount; + return set; +} diff --git a/src/QtLocationPlugin/MapProvider.h b/src/QtLocationPlugin/MapProvider.h index 79c1c6df14541a1e08c23edec4e0139307b76d89..4916fd74739fb4c5733207099afb572419342d52 100644 --- a/src/QtLocationPlugin/MapProvider.h +++ b/src/QtLocationPlugin/MapProvider.h @@ -1,5 +1,7 @@ #pragma once +#include "QGCTileSet.h" + #include #include #include @@ -35,6 +37,10 @@ class MapProvider : public QObject { virtual bool _isElevationProvider(); + virtual QGCTileSet getTileCount(int zoom, double topleftLon, + double topleftLat, double bottomRightLon, + double bottomRightLat); + protected: QString _tileXYToQuadKey(int tileX, int tileY, int levelOfDetail); int _getServerNum(int x, int y, int max); diff --git a/src/QtLocationPlugin/QGCLocationPlugin.pri b/src/QtLocationPlugin/QGCLocationPlugin.pri index b12ade44b4b6bf4f02e3ba8b9003907fff7d8733..6c62910ad39e846692aa68006e35faeb1aabe9e4 100644 --- a/src/QtLocationPlugin/QGCLocationPlugin.pri +++ b/src/QtLocationPlugin/QGCLocationPlugin.pri @@ -29,6 +29,8 @@ HEADERS += \ $$PWD/GenericMapProvider.h \ $$PWD/EsriMapProvider.h \ $$PWD/MapboxMapProvider.h \ + $$PWD/QGCTileSet.h \ + SOURCES += \ $$PWD/QGCMapEngine.cpp \ diff --git a/src/QtLocationPlugin/QGCMapEngine.cpp b/src/QtLocationPlugin/QGCMapEngine.cpp index 0eff56253aa13b21d18458ee27b2ca5b1ce08ec2..977a0bf823877087bebe3ebdbb6221d8d6eda328 100644 --- a/src/QtLocationPlugin/QGCMapEngine.cpp +++ b/src/QtLocationPlugin/QGCMapEngine.cpp @@ -250,22 +250,8 @@ QGCMapEngine::getTileCount(int zoom, double topleftLon, double topleftLat, doubl { if(zoom < 1) zoom = 1; if(zoom > MAX_MAP_ZOOM) zoom = MAX_MAP_ZOOM; - QGCTileSet set; - if(mapType != "Airmap Elevation"){ - set.tileX0 = getQGCMapEngine()->urlFactory()->long2tileX(mapType, topleftLon, zoom); - set.tileY0 = getQGCMapEngine()->urlFactory()->lat2tileY(mapType, topleftLat, zoom); - set.tileX1 = getQGCMapEngine()->urlFactory()->long2tileX(mapType, bottomRightLon, zoom); - set.tileY1 = getQGCMapEngine()->urlFactory()->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 set; + + return getQGCMapEngine()->urlFactory()->getTileCount(zoom, topleftLon, topleftLat, bottomRightLon, bottomRightLat, mapType); } diff --git a/src/QtLocationPlugin/QGCMapEngine.h b/src/QtLocationPlugin/QGCMapEngine.h index 643b8da0c349e72fa02f6ffe99a6f41e5a540d98..e6813a6aed49e2196702a4849c7ed2ce72f9c220 100644 --- a/src/QtLocationPlugin/QGCMapEngine.h +++ b/src/QtLocationPlugin/QGCMapEngine.h @@ -25,41 +25,6 @@ #include "QGCMapEngineData.h" #include "QGCTileCacheWorker.h" -//----------------------------------------------------------------------------- -class QGCTileSet -{ -public: - QGCTileSet() - { - clear(); - } - QGCTileSet& operator += (QGCTileSet& other) - { - tileX0 += other.tileX0; - tileX1 += other.tileX1; - tileY0 += other.tileY0; - tileY1 += other.tileY1; - tileCount += other.tileCount; - tileSize += other.tileSize; - return *this; - } - void clear() - { - tileX0 = 0; - tileX1 = 0; - tileY0 = 0; - tileY1 = 0; - tileCount = 0; - tileSize = 0; - } - - int tileX0; - int tileX1; - int tileY0; - int tileY1; - quint64 tileCount; - quint64 tileSize; -}; //----------------------------------------------------------------------------- class QGCMapEngine : public QObject diff --git a/src/QtLocationPlugin/QGCMapUrlEngine.cpp b/src/QtLocationPlugin/QGCMapUrlEngine.cpp index d0156eff06764eb28eb9e53747a4c9c1ba7de51f..a8b6869de51a4232e71aee3898c2760a839db37d 100644 --- a/src/QtLocationPlugin/QGCMapUrlEngine.cpp +++ b/src/QtLocationPlugin/QGCMapUrlEngine.cpp @@ -173,3 +173,24 @@ UrlFactory::lat2tileY(QString mapType, double lat, int z) return _providersTable[mapType]->lat2tileY(lat, 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); +} diff --git a/src/QtLocationPlugin/QGCMapUrlEngine.h b/src/QtLocationPlugin/QGCMapUrlEngine.h index 960a5c9713af46819e4b67e075cfb4427854ba34..2a0563be06d6d4189b0ad59724e80946b4bd4f97 100644 --- a/src/QtLocationPlugin/QGCMapUrlEngine.h +++ b/src/QtLocationPlugin/QGCMapUrlEngine.h @@ -49,7 +49,11 @@ public: int getIdFromType(QString type); QString getTypeFromId(int id); -private: + QGCTileSet getTileCount(int zoom, double topleftLon, double topleftLat, + double bottomRightLon, double bottomRightLat, + QString mapType); + + private: int _timeout; QHash _providersTable; void registerProvider(QString Name, MapProvider* provider); diff --git a/src/QtLocationPlugin/QGCTileSet.h b/src/QtLocationPlugin/QGCTileSet.h new file mode 100644 index 0000000000000000000000000000000000000000..fc38a4f52d4984ccfde564fe1840a37ddfb65a44 --- /dev/null +++ b/src/QtLocationPlugin/QGCTileSet.h @@ -0,0 +1,38 @@ +#pragma once +#include + +//----------------------------------------------------------------------------- +class QGCTileSet +{ +public: + QGCTileSet() + { + clear(); + } + QGCTileSet& operator += (QGCTileSet& other) + { + tileX0 += other.tileX0; + tileX1 += other.tileX1; + tileY0 += other.tileY0; + tileY1 += other.tileY1; + tileCount += other.tileCount; + tileSize += other.tileSize; + return *this; + } + void clear() + { + tileX0 = 0; + tileX1 = 0; + tileY0 = 0; + tileY1 = 0; + tileCount = 0; + tileSize = 0; + } + + int tileX0; + int tileX1; + int tileY0; + int tileY1; + quint64 tileCount; + quint64 tileSize; +};