Skip to content
Snippets Groups Projects
Commit 9f48f6a4 authored by Pierre TILAK's avatar Pierre TILAK
Browse files

Move getTileCount to MapProvider

parent 83d7845e
No related branches found
No related tags found
No related merge requests found
......@@ -37,3 +37,22 @@ AirmapElevationProvider::_getURL(int x, int y, int zoom,
.arg(static_cast<double>(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<quint64>(set.tileX1) -
static_cast<quint64>(set.tileX0) + 1) *
(static_cast<quint64>(set.tileY1) -
static_cast<quint64>(set.tileY0) + 1);
set.tileSize = getAverageSize() * set.tileCount;
return set;
}
......@@ -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:
......
......@@ -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<quint64>(set.tileX1) -
static_cast<quint64>(set.tileX0) + 1) *
(static_cast<quint64>(set.tileY1) -
static_cast<quint64>(set.tileY0) + 1);
set.tileSize = getAverageSize() * set.tileCount;
return set;
}
#pragma once
#include "QGCTileSet.h"
#include <QByteArray>
#include <QNetworkProxy>
#include <QNetworkReply>
......@@ -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);
......
......@@ -29,6 +29,8 @@ HEADERS += \
$$PWD/GenericMapProvider.h \
$$PWD/EsriMapProvider.h \
$$PWD/MapboxMapProvider.h \
$$PWD/QGCTileSet.h \
SOURCES += \
$$PWD/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<quint64>(set.tileX1) - static_cast<quint64>(set.tileX0) + 1) * (static_cast<quint64>(set.tileY1) - static_cast<quint64>(set.tileY0) + 1);
set.tileSize = getQGCMapEngine()->urlFactory()->averageSizeForType(mapType) * set.tileCount;
return set;
return getQGCMapEngine()->urlFactory()->getTileCount(zoom, topleftLon, topleftLat, bottomRightLon, bottomRightLat, mapType);
}
......
......@@ -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
......
......@@ -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<quint64>(set.tileX1) - static_cast<quint64>(set.tileX0) + 1) * (static_cast<quint64>(set.tileY1) - static_cast<quint64>(set.tileY0) + 1);
//set.tileSize = getQGCMapEngine()->urlFactory()->averageSizeForType(mapType) * set.tileCount;
return _providersTable[mapType]->getTileCount(zoom, topleftLon, topleftLat, bottomRightLon, bottomRightLat);
}
......@@ -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<QString, MapProvider*> _providersTable;
void registerProvider(QString Name, MapProvider* provider);
......
#pragma once
#include <QString>
//-----------------------------------------------------------------------------
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;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment