1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 19:55:53 +01: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 class Tile
{ {
public: public:
Tile(const QPoint &xy, int zoom) Tile(const QPoint &xy, const QVariant &zoom)
{_xy = xy; _zoom = zoom;} {_xy = xy; _zoom = zoom;}
int zoom() const {return _zoom;} QVariant zoom() const {return _zoom;}
const QPoint& xy() const {return _xy;} const QPoint& xy() const {return _xy;}
QPixmap& pixmap() {return _pixmap;} QPixmap& pixmap() {return _pixmap;}
private: private:
int _zoom; QVariant _zoom;
QPoint _xy; QPoint _xy;
QPixmap _pixmap; QPixmap _pixmap;
}; };

View File

@ -90,7 +90,7 @@ QString TileLoader::tileUrl(const Tile &tile) const
{ {
QString url(_url); 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("$x", QString::number(tile.xy().x()));
url.replace("$y", QString::number(tile.xy().y())); 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 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()); .arg(tile.xy().x()).arg(tile.xy().y());
return file; return file;

View File

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

View File

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

View File

@ -108,9 +108,14 @@ void WMTSMap::emitLoaded()
QRectF WMTSMap::bounds() const QRectF WMTSMap::bounds() const
{ {
const WMTS::Zoom &z = _zooms.at(_zoom); const WMTS::Zoom &z = _zooms.at(_zoom);
return QRectF(QPointF(z.limits.left() * z.tile.width(), z.limits.top()
* z.tile.height()), QSize(z.tile.width() * z.limits.width(), if (z.limits.isNull())
z.tile.height() * z.limits.height())); 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()));
} }
qreal WMTSMap::zoomFit(const QSize &size, const RectC &br) qreal WMTSMap::zoomFit(const QSize &size, const RectC &br)
@ -184,7 +189,7 @@ void WMTSMap::draw(QPainter *painter, const QRectF &rect)
QList<Tile> tiles; QList<Tile> tiles;
for (int i = tl.x(); i < br.x(); i++) for (int i = tl.x(); i < br.x(); i++)
for (int j = tl.y(); j < br.y(); j++) 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) if (_block)
_tileLoader.loadTilesSync(tiles); _tileLoader.loadTilesSync(tiles);