2018-02-20 23:37:19 +01:00
|
|
|
#ifndef WMTS_H
|
|
|
|
#define WMTS_H
|
|
|
|
|
|
|
|
#include <QSize>
|
2018-02-24 16:48:38 +01:00
|
|
|
#include <QRect>
|
2018-02-24 16:44:30 +01:00
|
|
|
#include <QSet>
|
2018-02-24 10:34:27 +01:00
|
|
|
#include <QList>
|
2018-02-24 16:44:30 +01:00
|
|
|
#include <QHash>
|
2021-01-10 13:23:43 +01:00
|
|
|
#include "common/config.h"
|
2018-02-24 16:44:30 +01:00
|
|
|
#include "common/rectc.h"
|
2018-09-30 12:16:41 +02:00
|
|
|
#include "common/kv.h"
|
2018-02-20 23:37:19 +01:00
|
|
|
#include "projection.h"
|
2018-04-01 20:01:25 +02:00
|
|
|
#include "downloader.h"
|
2018-04-05 21:13:48 +02:00
|
|
|
#include "coordinatesystem.h"
|
2018-02-20 23:37:19 +01:00
|
|
|
|
2018-02-27 21:50:29 +01:00
|
|
|
class QXmlStreamReader;
|
2018-02-20 23:37:19 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
class WMTS : public QObject
|
2018-02-20 23:37:19 +01:00
|
|
|
{
|
2020-03-17 21:06:51 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2018-02-20 23:37:19 +01:00
|
|
|
public:
|
2018-03-30 10:25:05 +02:00
|
|
|
class Setup
|
|
|
|
{
|
|
|
|
public:
|
2018-02-25 02:31:01 +01:00
|
|
|
Setup(const QString &url, const QString &layer, const QString &set,
|
2018-04-05 20:38:23 +02:00
|
|
|
const QString &style, const QString &format, bool rest,
|
2019-08-01 08:36:58 +02:00
|
|
|
const CoordinateSystem &cs,
|
|
|
|
const QList<KV<QString, QString> > &dimensions,
|
2018-04-07 18:42:25 +02:00
|
|
|
const Authorization &authorization = Authorization())
|
|
|
|
: _url(url), _layer(layer), _set(set), _style(style),
|
|
|
|
_format(format), _rest(rest), _cs(cs), _dimensions(dimensions),
|
|
|
|
_authorization(authorization) {}
|
2018-03-30 10:25:05 +02:00
|
|
|
|
|
|
|
const QString &url() const {return _url;}
|
2018-04-01 20:01:25 +02:00
|
|
|
const Authorization &authorization() const {return _authorization;}
|
2018-03-30 10:25:05 +02:00
|
|
|
const QString &layer() const {return _layer;}
|
|
|
|
const QString &set() const {return _set;}
|
|
|
|
const QString &style() const {return _style;}
|
|
|
|
const QString &format() const {return _format;}
|
|
|
|
bool rest() const {return _rest;}
|
2018-04-07 18:42:25 +02:00
|
|
|
const CoordinateSystem &coordinateSystem() const {return _cs;}
|
2019-08-01 08:36:58 +02:00
|
|
|
const QList<KV<QString, QString> > &dimensions() const
|
|
|
|
{return _dimensions;}
|
2018-03-30 10:25:05 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
QString _url;
|
|
|
|
QString _layer;
|
|
|
|
QString _set;
|
|
|
|
QString _style;
|
|
|
|
QString _format;
|
|
|
|
bool _rest;
|
2018-04-07 18:42:25 +02:00
|
|
|
CoordinateSystem _cs;
|
2019-08-01 08:36:58 +02:00
|
|
|
QList<KV<QString, QString> > _dimensions;
|
2018-04-01 20:01:25 +02:00
|
|
|
Authorization _authorization;
|
2018-02-25 02:31:01 +01:00
|
|
|
};
|
|
|
|
|
2018-03-30 10:25:05 +02:00
|
|
|
class Zoom
|
|
|
|
{
|
|
|
|
public:
|
2018-04-15 16:27:47 +02:00
|
|
|
Zoom(const QString &id, double scaleDenominator, const PointD &topLeft,
|
2018-02-24 16:44:30 +01:00
|
|
|
const QSize &tile, const QSize &matrix, const QRect &limits) :
|
2018-03-30 10:25:05 +02:00
|
|
|
_id(id), _scaleDenominator(scaleDenominator), _topLeft(topLeft),
|
|
|
|
_tile(tile), _matrix(matrix), _limits(limits) {}
|
2018-02-24 10:34:27 +01:00
|
|
|
bool operator<(const Zoom &other) const
|
2018-03-30 10:25:05 +02:00
|
|
|
{return _scaleDenominator > other._scaleDenominator;}
|
|
|
|
|
|
|
|
const QString &id() const {return _id;}
|
2018-04-13 21:14:12 +02:00
|
|
|
double scaleDenominator() const {return _scaleDenominator;}
|
2018-04-15 16:27:47 +02:00
|
|
|
const PointD &topLeft() const {return _topLeft;}
|
2018-03-30 10:25:05 +02:00
|
|
|
const QSize &tile() const {return _tile;}
|
|
|
|
const QSize &matrix() const {return _matrix;}
|
|
|
|
const QRect &limits() const {return _limits;}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _id;
|
2018-04-13 21:14:12 +02:00
|
|
|
double _scaleDenominator;
|
2018-04-15 16:27:47 +02:00
|
|
|
PointD _topLeft;
|
2018-03-30 10:25:05 +02:00
|
|
|
QSize _tile;
|
|
|
|
QSize _matrix;
|
|
|
|
QRect _limits;
|
2018-02-20 23:37:19 +01:00
|
|
|
};
|
|
|
|
|
2018-03-30 10:25:05 +02:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
WMTS(const QString &path, const Setup &setup, QObject *parent = 0);
|
2018-02-20 23:37:19 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
const RectC &bbox() const {return _bbox;}
|
2018-10-15 00:20:20 +02:00
|
|
|
const QList<Zoom> &zooms() const {return _zooms;}
|
2018-02-24 01:59:03 +01:00
|
|
|
const Projection &projection() const {return _projection;}
|
2018-03-30 10:25:05 +02:00
|
|
|
const QString &tileUrl() const {return _tileUrl;}
|
2020-03-17 21:06:51 +01:00
|
|
|
CoordinateSystem cs() const {return _cs;}
|
2018-03-30 10:25:05 +02:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
bool isReady() const {return _valid && _ready;}
|
2018-03-30 10:25:05 +02:00
|
|
|
bool isValid() const {return _valid;}
|
|
|
|
const QString &errorString() const {return _errorString;}
|
2018-02-20 23:37:19 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
signals:
|
|
|
|
void downloadFinished();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void capabilitiesReady();
|
|
|
|
|
2018-02-20 23:37:19 +01:00
|
|
|
private:
|
2018-02-24 16:44:30 +01:00
|
|
|
struct TileMatrix {
|
|
|
|
QString id;
|
2018-04-13 21:14:12 +02:00
|
|
|
double scaleDenominator;
|
2018-04-15 16:27:47 +02:00
|
|
|
PointD topLeft;
|
2018-02-24 16:44:30 +01:00
|
|
|
QSize tile;
|
|
|
|
QSize matrix;
|
|
|
|
|
|
|
|
TileMatrix() : scaleDenominator(0) {}
|
|
|
|
bool operator==(const TileMatrix &other) const
|
|
|
|
{return this->id == other.id;}
|
|
|
|
bool isValid() const
|
|
|
|
{return !id.isEmpty() && scaleDenominator > 0 && tile.isValid()
|
|
|
|
&& matrix.isValid();}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MatrixLimits {
|
|
|
|
QString id;
|
|
|
|
QRect rect;
|
|
|
|
|
|
|
|
MatrixLimits() {}
|
|
|
|
MatrixLimits(const QString &id) : id(id) {}
|
|
|
|
bool operator==(const MatrixLimits &other) const
|
|
|
|
{return this->id == other.id;}
|
|
|
|
bool isValid() const
|
|
|
|
{return !id.isEmpty() && rect.isValid();}
|
|
|
|
};
|
|
|
|
|
2018-02-26 22:35:58 +01:00
|
|
|
struct CTX {
|
2018-10-15 00:20:20 +02:00
|
|
|
QSet<TileMatrix> matrixes;
|
|
|
|
QSet<MatrixLimits> limits;
|
2018-02-26 22:35:58 +01:00
|
|
|
QString crs;
|
2018-10-15 00:20:20 +02:00
|
|
|
QString defaultStyle;
|
2020-03-17 21:06:51 +01:00
|
|
|
RectC bbox;
|
2018-04-03 22:35:13 +02:00
|
|
|
bool hasLayer;
|
|
|
|
bool hasStyle;
|
|
|
|
bool hasFormat;
|
|
|
|
bool hasSet;
|
2018-02-26 22:35:58 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
CTX() : hasLayer(false), hasStyle(false), hasFormat(false), hasSet(false)
|
|
|
|
{}
|
2018-02-26 22:35:58 +01:00
|
|
|
};
|
|
|
|
|
2018-02-24 16:44:30 +01:00
|
|
|
RectC wgs84BoundingBox(QXmlStreamReader &reader);
|
|
|
|
MatrixLimits tileMatrixLimits(QXmlStreamReader &reader);
|
2018-04-05 20:38:23 +02:00
|
|
|
TileMatrix tileMatrix(QXmlStreamReader &reader);
|
2018-02-24 16:44:30 +01:00
|
|
|
QSet<MatrixLimits> tileMatrixSetLimits(QXmlStreamReader &reader);
|
2018-02-26 22:35:58 +01:00
|
|
|
QString style(QXmlStreamReader &reader);
|
2018-02-27 21:50:29 +01:00
|
|
|
void tileMatrixSet(QXmlStreamReader &reader, CTX &ctx);
|
|
|
|
void tileMatrixSetLink(QXmlStreamReader &reader, CTX &ctx);
|
|
|
|
void layer(QXmlStreamReader &reader, CTX &ctx);
|
|
|
|
void contents(QXmlStreamReader &reader, CTX &ctx);
|
|
|
|
void capabilities(QXmlStreamReader &reader, CTX &ctx);
|
2020-03-17 21:06:51 +01:00
|
|
|
bool parseCapabilities(CTX &ctx);
|
|
|
|
bool downloadCapabilities(const QString &url);
|
2018-10-15 00:20:20 +02:00
|
|
|
void createZooms(const CTX &ctx);
|
2020-03-17 21:06:51 +01:00
|
|
|
bool init();
|
2018-02-20 23:37:19 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
WMTS::Setup _setup;
|
|
|
|
QString _path;
|
|
|
|
Downloader *_downloader;
|
|
|
|
RectC _bbox;
|
2018-10-15 00:20:20 +02:00
|
|
|
QList<Zoom> _zooms;
|
2018-02-20 23:37:19 +01:00
|
|
|
Projection _projection;
|
2018-02-25 02:31:01 +01:00
|
|
|
QString _tileUrl;
|
2020-03-17 21:06:51 +01:00
|
|
|
CoordinateSystem _cs;
|
2018-02-20 23:37:19 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
bool _valid, _ready;
|
2018-02-20 23:37:19 +01:00
|
|
|
QString _errorString;
|
|
|
|
|
2021-01-10 13:23:43 +01:00
|
|
|
friend HASH_T qHash(const WMTS::TileMatrix &key);
|
|
|
|
friend HASH_T qHash(const WMTS::MatrixLimits &key);
|
2018-02-20 23:37:19 +01:00
|
|
|
};
|
|
|
|
|
2021-01-10 13:23:43 +01:00
|
|
|
inline HASH_T qHash(const WMTS::TileMatrix &key)
|
2018-02-24 16:44:30 +01:00
|
|
|
{
|
|
|
|
return ::qHash(key.id);
|
|
|
|
}
|
|
|
|
|
2021-01-10 13:23:43 +01:00
|
|
|
inline HASH_T qHash(const WMTS::MatrixLimits &key)
|
2018-02-24 16:44:30 +01:00
|
|
|
{
|
|
|
|
return ::qHash(key.id);
|
|
|
|
}
|
|
|
|
|
2018-02-24 01:59:03 +01:00
|
|
|
#ifndef QT_NO_DEBUG
|
2018-02-25 02:31:01 +01:00
|
|
|
QDebug operator<<(QDebug dbg, const WMTS::Setup &setup);
|
2018-02-24 01:59:03 +01:00
|
|
|
QDebug operator<<(QDebug dbg, const WMTS::Zoom &zoom);
|
|
|
|
#endif // QT_NO_DEBUG
|
|
|
|
|
2018-02-20 23:37:19 +01:00
|
|
|
#endif // WMTS_H
|