1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 14:53:21 +02:00

Properly handling non-integer tile matrix ids

This commit is contained in:
Martin Tůma 2018-02-24 10:34:27 +01:00
parent d11ffc9ea4
commit 376587202b
5 changed files with 34 additions and 16 deletions

View File

@ -8,15 +8,15 @@
class Tile
{
public:
Tile(const QPoint &xy, int zoom)
Tile(const QPoint &xy, const QVariant &zoom)
{_xy = xy; _zoom = zoom;}
int zoom() const {return _zoom;}
QVariant zoom() const {return _zoom;}
const QPoint& xy() const {return _xy;}
QPixmap& pixmap() {return _pixmap;}
private:
int _zoom;
QVariant _zoom;
QPoint _xy;
QPixmap _pixmap;
};

View File

@ -90,7 +90,7 @@ QString TileLoader::tileUrl(const Tile &tile) const
{
QString url(_url);
url.replace("$z", QString::number(tile.zoom()));
url.replace("$z", tile.zoom().toString());
url.replace("$x", QString::number(tile.xy().x()));
url.replace("$y", QString::number(tile.xy().y()));
@ -99,7 +99,7 @@ QString TileLoader::tileUrl(const Tile &tile) const
QString TileLoader::tileFile(const Tile &tile) const
{
QString file = _dir + QString("/%1-%2-%3").arg(tile.zoom())
QString file = _dir + QString("/%1-%2-%3").arg(tile.zoom().toString())
.arg(tile.xy().x()).arg(tile.xy().y());
return file;

View File

@ -4,6 +4,7 @@
#include <QEventLoop>
#include <QTextStream>
#include <QStringList>
#include <QtAlgorithms>
#include "downloader.h"
#include "pcs.h"
#include "wmts.h"
@ -52,12 +53,11 @@ bool WMTS::createProjection(const QString &crs)
void WMTS::tileMatrix(QXmlStreamReader &reader)
{
int id;
Zoom zoom;
while (reader.readNextStartElement()) {
if (reader.name() == "Identifier")
id = reader.readElementText().toInt();
zoom.id = reader.readElementText();
else if (reader.name() == "ScaleDenominator")
zoom.scaleDenominator = reader.readElementText().toDouble();
else if (reader.name() == "TopLeftCorner") {
@ -75,7 +75,8 @@ void WMTS::tileMatrix(QXmlStreamReader &reader)
reader.skipCurrentElement();
}
Zoom &z = _zooms[id];
Zoom &z = _zooms[zoom.id];
z.id = zoom.id;
z.matrix = zoom.matrix;
z.scaleDenominator = zoom.scaleDenominator;
z.tile = zoom.tile;
@ -101,12 +102,12 @@ void WMTS::tileMatrixSet(QXmlStreamReader &reader, const QString &set)
void WMTS::tileMatrixLimits(QXmlStreamReader &reader)
{
int id;
QString id;
QRect limits;
while (reader.readNextStartElement()) {
if (reader.name() == "TileMatrix")
id = reader.readElementText().toInt();
id = reader.readElementText();
else if (reader.name() == "MinTileRow")
limits.setTop(reader.readElementText().toInt());
else if (reader.name() == "MaxTileRow")
@ -253,6 +254,13 @@ bool WMTS::load(const QString &file, const QString &url, const QString &layer,
return true;
}
QList<WMTS::Zoom> WMTS::zooms() const
{
QList<Zoom> z(_zooms.values());
qSort(z);
return z;
}
#ifndef QT_NO_DEBUG
QDebug operator<<(QDebug dbg, const WMTS::Zoom &zoom)
{

View File

@ -3,6 +3,7 @@
#include <QSize>
#include <QMap>
#include <QList>
#include "projection.h"
class QXmlStreamReader;
@ -12,18 +13,22 @@ class WMTS
{
public:
struct Zoom {
QString id;
qreal scaleDenominator;
QPointF topLeft;
QSize tile;
QSize matrix;
QRect limits;
bool operator<(const Zoom &other) const
{return this->scaleDenominator > other.scaleDenominator;}
};
bool load(const QString &path, const QString &url, const QString &layer,
const QString &set);
const QString &errorString() const {return _errorString;}
const QList<Zoom> zooms() const {return _zooms.values();}
QList<Zoom> zooms() const;
const Projection &projection() const {return _projection;}
static Downloader *downloader() {return _downloader;}
@ -48,7 +53,7 @@ private:
const QString &set);
bool getCapabilities(const QString &url, const QString &file);
QMap<int, Zoom> _zooms;
QMap<QString, Zoom> _zooms;
Projection _projection;
QString _errorString;

View File

@ -108,6 +108,11 @@ void WMTSMap::emitLoaded()
QRectF WMTSMap::bounds() const
{
const WMTS::Zoom &z = _zooms.at(_zoom);
if (z.limits.isNull())
return QRectF(QPointF(0, 0), QSize(z.tile.width() * z.matrix.width(),
z.tile.height() * z.matrix.height()));
else
return QRectF(QPointF(z.limits.left() * z.tile.width(), z.limits.top()
* z.tile.height()), QSize(z.tile.width() * z.limits.width(),
z.tile.height() * z.limits.height()));
@ -184,7 +189,7 @@ void WMTSMap::draw(QPainter *painter, const QRectF &rect)
QList<Tile> tiles;
for (int i = tl.x(); i < br.x(); i++)
for (int j = tl.y(); j < br.y(); j++)
tiles.append(Tile(QPoint(i, j), _zoom));
tiles.append(Tile(QPoint(i, j), z.id));
if (_block)
_tileLoader.loadTilesSync(tiles);