1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 19:55:53 +01:00

Added support for QuadTiles maps

This commit is contained in:
Martin Tůma 2019-05-20 23:23:24 +02:00
parent 681c83d017
commit 5b2af9fc9c
8 changed files with 58 additions and 27 deletions

View File

@ -160,6 +160,8 @@ void MapSource::map(QXmlStreamReader &reader, Config &config)
config.type = WMS;
else if (type == "TMS")
config.type = TMS;
else if (type == "QuadTiles")
config.type = QuadTiles;
else if (type == "OSM" || type.isEmpty())
config.type = OSM;
else {
@ -293,11 +295,15 @@ Map *MapSource::loadMap(const QString &path, QString &errorString)
case TMS:
return new OnlineMap(config.name, config.url, config.zooms,
config.bounds, config.tileRatio, config.authorization,
config.tileSize, config.scalable, true);
config.tileSize, config.scalable, true, false);
case OSM:
return new OnlineMap(config.name, config.url, config.zooms,
config.bounds, config.tileRatio, config.authorization,
config.tileSize, config.scalable, false);
config.tileSize, config.scalable, false, false);
case QuadTiles:
return new OnlineMap(config.name, config.url, config.zooms,
config.bounds, config.tileRatio, config.authorization,
config.tileSize, config.scalable, false, true);
default:
return 0;
}

View File

@ -21,7 +21,8 @@ private:
OSM,
WMTS,
WMS,
TMS
TMS,
QuadTiles
};
struct Config {

View File

@ -11,15 +11,16 @@
OnlineMap::OnlineMap(const QString &name, const QString &url,
const Range &zooms, const RectC &bounds, qreal tileRatio,
const Authorization &authorization, int tileSize, bool scalable, bool invertY,
QObject *parent)
bool quadTiles, QObject *parent)
: Map(parent), _name(name), _zooms(zooms), _bounds(bounds),
_zoom(_zooms.max()), _mapRatio(1.0), _tileRatio(tileRatio),
_tileSize(tileSize), _scalable(scalable), _invertY(invertY), _scaledSize(0)
_tileSize(tileSize), _scalable(scalable), _invertY(invertY)
{
_tileLoader = new TileLoader(QDir(ProgramPaths::tilesDir()).filePath(_name),
this);
_tileLoader->setUrl(url);
_tileLoader->setAuthorization(authorization);
_tileLoader->setQuadTiles(quadTiles);
connect(_tileLoader, SIGNAL(finished()), this, SIGNAL(loaded()));
}
@ -74,7 +75,7 @@ void OnlineMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
_mapRatio = mapRatio;
if (_scalable) {
_scaledSize = _tileSize * deviceRatio;
_tileLoader->setScaledSize(_tileSize * deviceRatio);
_tileRatio = deviceRatio;
}
}
@ -112,7 +113,7 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
for (int i = 0; i < width; i++)
for (int j = 0; j < height; j++)
tiles.append(Tile(QPoint(tile.x() + i, _invertY ? (1<<_zoom)
- (tile.y() + j) - 1 : tile.y() + j), _zoom, _scaledSize));
- (tile.y() + j) - 1 : tile.y() + j), _zoom));
if (flags & Map::Block)
_tileLoader->loadTilesSync(tiles);

View File

@ -13,7 +13,8 @@ class OnlineMap : public Map
public:
OnlineMap(const QString &name, const QString &url, const Range &zooms,
const RectC &bounds, qreal tileRatio, const Authorization &authorization,
int tileSize, bool scalable, bool invertY, QObject *parent = 0);
int tileSize, bool scalable, bool invertY, bool quadTiles,
QObject *parent = 0);
QString name() const {return _name;}
@ -49,7 +50,6 @@ private:
int _tileSize;
bool _scalable;
bool _invertY;
int _scaledSize;
};
#endif // ONLINEMAP_H

View File

@ -10,21 +10,18 @@
class Tile
{
public:
Tile() : _scaledSize(0) {}
Tile(const QPoint &xy, const QVariant &zoom, int scaledSize = 0,
const RectD &bbox = RectD()) : _xy(xy), _zoom(zoom),
_scaledSize(scaledSize), _bbox(bbox) {}
Tile() {}
Tile(const QPoint &xy, const QVariant &zoom, const RectD &bbox = RectD())
: _xy(xy), _zoom(zoom), _bbox(bbox) {}
const QVariant &zoom() const {return _zoom;}
const QPoint &xy() const {return _xy;}
const RectD &bbox() const {return _bbox;}
int scaledSize() const {return _scaledSize;}
QPixmap& pixmap() {return _pixmap;}
private:
QPoint _xy;
QVariant _zoom;
int _scaledSize;
RectD _bbox;
QPixmap _pixmap;
};

View File

@ -14,9 +14,9 @@
class TileImage
{
public:
TileImage() : _tile(0) {}
TileImage(const QString &file, Tile *tile)
: _file(file), _tile(tile) {}
TileImage() : _tile(0), _scaledSize(0) {}
TileImage(const QString &file, Tile *tile, int scaledSize)
: _file(file), _tile(tile), _scaledSize(scaledSize) {}
void createPixmap()
{
@ -26,8 +26,8 @@ public:
{
QByteArray z(_tile->zoom().toString().toLatin1());
QImageReader reader(_file, z);
if (_tile->scaledSize())
reader.setScaledSize(QSize(_tile->scaledSize(), _tile->scaledSize()));
if (_scaledSize)
reader.setScaledSize(QSize(_scaledSize, _scaledSize));
reader.read(&_image);
}
@ -37,6 +37,7 @@ public:
private:
QString _file;
Tile *_tile;
int _scaledSize;
QImage _image;
};
@ -45,8 +46,27 @@ static void render(TileImage &ti)
ti.load();
}
static QString quadKey(const QPoint &xy, int zoom)
{
QString qk;
for (int i = zoom; i > 0; i--) {
char digit = '0';
unsigned mask = 1 << (i - 1);
if (xy.x() & mask)
digit++;
if (xy.y() & mask) {
digit++;
digit++;
}
qk.append(digit);
}
return qk;
}
TileLoader::TileLoader(const QString &dir, QObject *parent)
: QObject(parent), _dir(dir)
: QObject(parent), _dir(dir), _scaledSize(0), _quadTiles(false)
{
if (!QDir().mkpath(_dir))
qWarning("%s: %s", qPrintable(_dir), "Error creating tiles directory");
@ -70,11 +90,11 @@ void TileLoader::loadTilesAsync(QVector<Tile> &list)
QFileInfo fi(file);
if (fi.exists())
imgs.append(TileImage(file, &t));
imgs.append(TileImage(file, &t, _scaledSize));
else {
QUrl url(tileUrl(t));
if (url.isLocalFile())
imgs.append(TileImage(url.toLocalFile(), &t));
imgs.append(TileImage(url.toLocalFile(), &t, _scaledSize));
else
dl.append(Download(url, file));
}
@ -109,11 +129,11 @@ void TileLoader::loadTilesSync(QVector<Tile> &list)
QFileInfo fi(file);
if (fi.exists())
imgs.append(TileImage(file, &t));
imgs.append(TileImage(file, &t, _scaledSize));
else {
QUrl url(tileUrl(t));
if (url.isLocalFile())
imgs.append(TileImage(url.toLocalFile(), &t));
imgs.append(TileImage(url.toLocalFile(), &t, _scaledSize));
else {
dl.append(Download(url, file));
tl.append(&t);
@ -131,7 +151,7 @@ void TileLoader::loadTilesSync(QVector<Tile> &list)
Tile *t = tl[i];
QString file = tileFile(*t);
if (QFileInfo(file).exists())
imgs.append(TileImage(file, t));
imgs.append(TileImage(file, t, _scaledSize));
}
}
@ -164,6 +184,8 @@ QUrl TileLoader::tileUrl(const Tile &tile) const
QString::number(tile.bbox().right(), 'f', 6),
QString::number(tile.bbox().top(), 'f', 6));
url.replace("$bbox", bbox);
} else if (_quadTiles) {
url.replace("$quadkey", quadKey(tile.xy(), tile.zoom().toInt()));
} else {
url.replace("$z", tile.zoom().toString());
url.replace("$x", QString::number(tile.xy().x()));

View File

@ -16,6 +16,8 @@ public:
void setUrl(const QString &url) {_url = url;}
void setAuthorization(const Authorization &authorization)
{_authorization = authorization;}
void setScaledSize(int size) {_scaledSize = size;}
void setQuadTiles(bool quadTiles) {_quadTiles = quadTiles;}
void loadTilesAsync(QVector<Tile> &list);
void loadTilesSync(QVector<Tile> &list);
@ -32,6 +34,8 @@ private:
QString _url;
QString _dir;
Authorization _authorization;
int _scaledSize;
bool _quadTiles;
};
#endif // TILELOADER_Honlinemap

View File

@ -200,7 +200,7 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
? RectD(PointD(tbr.y(), tbr.x()), PointD(ttl.y(), ttl.x()))
: RectD(ttl, tbr);
tiles.append(Tile(QPoint(i, j), _zoom, 0, bbox));
tiles.append(Tile(QPoint(i, j), _zoom, bbox));
}
}