1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 07:13:21 +02:00
GPXSee/src/map/wmts.h

173 lines
4.6 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>
#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:
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,
2018-09-30 12:16:41 +02:00
const CoordinateSystem &cs, const QList<KV> &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;}
2018-09-30 12:16:41 +02:00
const QList<KV> &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;
2018-09-30 12:16:41 +02:00
QList<KV> _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);
2018-02-20 23:37:19 +01:00
const RectC &bounds() const {return _bounds;}
QList<Zoom> zooms() const;
const Projection &projection() const {return _projection;}
const QString &tileUrl() const {return _tileUrl;}
bool isValid() const {return _valid;}
const QString &errorString() const {return _errorString;}
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 {
const Setup &setup;
QString crs;
bool hasLayer;
bool hasStyle;
bool hasFormat;
bool hasSet;
2018-02-26 22:35:58 +01:00
CTX(const Setup &setup) : setup(setup), 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);
2018-02-26 22:35:58 +01:00
bool parseCapabilities(const QString &path, const Setup &setup);
2018-09-22 12:42:49 +02:00
bool downloadCapabilities(const QString &url, const QString &file,
const Authorization &authorization);
2018-02-20 23:37:19 +01:00
QSet<TileMatrix> _matrixes;
QSet<MatrixLimits> _limits;
RectC _bounds;
2018-02-20 23:37:19 +01:00
Projection _projection;
2018-02-25 02:31:01 +01:00
QString _tileUrl;
2018-02-20 23:37:19 +01:00
bool _valid;
2018-02-20 23:37:19 +01:00
QString _errorString;
friend uint qHash(const WMTS::TileMatrix &key);
friend uint qHash(const WMTS::MatrixLimits &key);
2018-02-20 23:37:19 +01:00
};
inline uint qHash(const WMTS::TileMatrix &key)
{
return ::qHash(key.id);
}
inline uint 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