diff --git a/src/map/tile.h b/src/map/tile.h index 96861627..af27780b 100644 --- a/src/map/tile.h +++ b/src/map/tile.h @@ -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; }; diff --git a/src/map/tileloader.cpp b/src/map/tileloader.cpp index f3f547c6..70f29da9 100644 --- a/src/map/tileloader.cpp +++ b/src/map/tileloader.cpp @@ -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; diff --git a/src/map/wmts.cpp b/src/map/wmts.cpp index 5f745044..8aa8106f 100644 --- a/src/map/wmts.cpp +++ b/src/map/wmts.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #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::zooms() const +{ + QList z(_zooms.values()); + qSort(z); + return z; +} + #ifndef QT_NO_DEBUG QDebug operator<<(QDebug dbg, const WMTS::Zoom &zoom) { diff --git a/src/map/wmts.h b/src/map/wmts.h index d82ea13f..98e4030c 100644 --- a/src/map/wmts.h +++ b/src/map/wmts.h @@ -3,6 +3,7 @@ #include #include +#include #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 zooms() const {return _zooms.values();} + QList 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 _zooms; + QMap _zooms; Projection _projection; QString _errorString; diff --git a/src/map/wmtsmap.cpp b/src/map/wmtsmap.cpp index e4a27e3b..255f7dee 100644 --- a/src/map/wmtsmap.cpp +++ b/src/map/wmtsmap.cpp @@ -108,9 +108,14 @@ void WMTSMap::emitLoaded() QRectF WMTSMap::bounds() const { 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(), - z.tile.height() * z.limits.height())); + + 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())); } qreal WMTSMap::zoomFit(const QSize &size, const RectC &br) @@ -184,7 +189,7 @@ void WMTSMap::draw(QPainter *painter, const QRectF &rect) QList 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);