1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-12-11 03:29:09 +01:00
GPXSee/src/map/wmts.h

193 lines
5.0 KiB
C
Raw Normal View History

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>
#include <QSet>
#include <QList>
#include <QHash>
2021-01-10 13:23:43 +01:00
#include "common/config.h"
#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"
#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
class WMTS : public QObject
2018-02-20 23:37:19 +01:00
{
Q_OBJECT
2018-02-20 23:37:19 +01:00
public:
class Setup
{
public:
2018-02-25 02:31:01 +01:00
Setup(const QString &url, const QString &layer, const QString &set,
const QString &style, const QString &format, bool rest,
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) {}
const QString &url() const {return _url;}
const Authorization &authorization() const {return _authorization;}
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;}
const QList<KV<QString, QString> > &dimensions() const
{return _dimensions;}
private:
QString _url;
QString _layer;
QString _set;
QString _style;
QString _format;
bool _rest;
2018-04-07 18:42:25 +02:00
CoordinateSystem _cs;
QList<KV<QString, QString> > _dimensions;
Authorization _authorization;
2018-02-25 02:31:01 +01:00
};
class Zoom
{
public:
Zoom(const QString &id, double scaleDenominator, const PointD &topLeft,
const QSize &tile, const QSize &matrix, const QRect &limits) :
_id(id), _scaleDenominator(scaleDenominator), _topLeft(topLeft),
_tile(tile), _matrix(matrix), _limits(limits) {}
bool operator<(const Zoom &other) const
{return _scaleDenominator > other._scaleDenominator;}
const QString &id() const {return _id;}
double scaleDenominator() const {return _scaleDenominator;}
const PointD &topLeft() const {return _topLeft;}
const QSize &tile() const {return _tile;}
const QSize &matrix() const {return _matrix;}
const QRect &limits() const {return _limits;}
private:
QString _id;
double _scaleDenominator;
PointD _topLeft;
QSize _tile;
QSize _matrix;
QRect _limits;
2018-02-20 23:37:19 +01:00
};
WMTS(const QString &path, const Setup &setup, QObject *parent = 0);
2018-02-20 23:37:19 +01:00
const RectC &bbox() const {return _bbox;}
const QList<Zoom> &zooms() const {return _zooms;}
const Projection &projection() const {return _projection;}
const QString &tileUrl() const {return _tileUrl;}
CoordinateSystem cs() const {return _cs;}
bool isReady() const {return _valid && _ready;}
bool isValid() const {return _valid;}
const QString &errorString() const {return _errorString;}
2018-02-20 23:37:19 +01:00
signals:
void downloadFinished();
private slots:
void capabilitiesReady();
2018-02-20 23:37:19 +01:00
private:
struct TileMatrix {
QString id;
double scaleDenominator;
PointD topLeft;
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 {
QSet<TileMatrix> matrixes;
QSet<MatrixLimits> limits;
2018-02-26 22:35:58 +01:00
QString crs;
QString defaultStyle;
RectC bbox;
bool hasLayer;
bool hasStyle;
bool hasFormat;
bool hasSet;
2018-02-26 22:35:58 +01:00
CTX() : hasLayer(false), hasStyle(false), hasFormat(false), hasSet(false)
{}
2018-02-26 22:35:58 +01:00
};
RectC wgs84BoundingBox(QXmlStreamReader &reader);
MatrixLimits tileMatrixLimits(QXmlStreamReader &reader);
TileMatrix tileMatrix(QXmlStreamReader &reader);
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);
bool parseCapabilities(CTX &ctx);
bool downloadCapabilities(const QString &url);
void createZooms(const CTX &ctx);
bool init();
2018-02-20 23:37:19 +01:00
WMTS::Setup _setup;
QString _path;
Downloader *_downloader;
RectC _bbox;
QList<Zoom> _zooms;
2018-02-20 23:37:19 +01:00
Projection _projection;
2018-02-25 02:31:01 +01:00
QString _tileUrl;
CoordinateSystem _cs;
2018-02-20 23:37:19 +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)
{
return ::qHash(key.id);
}
2021-01-10 13:23:43 +01:00
inline HASH_T qHash(const WMTS::MatrixLimits &key)
{
return ::qHash(key.id);
}
#ifndef QT_NO_DEBUG
2018-02-25 02:31:01 +01:00
QDebug operator<<(QDebug dbg, const WMTS::Setup &setup);
QDebug operator<<(QDebug dbg, const WMTS::Zoom &zoom);
#endif // QT_NO_DEBUG
2018-02-20 23:37:19 +01:00
#endif // WMTS_H