1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 23:03:22 +02:00
GPXSee/src/map/wmts.h

148 lines
3.5 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>
2018-02-26 22:35:58 +01:00
#include <QXmlStreamReader>
#include "common/rectc.h"
2018-02-20 23:37:19 +01:00
#include "projection.h"
class Downloader;
class WMTS
{
public:
2018-02-25 02:31:01 +01:00
struct Setup {
QString url;
QString layer;
QString set;
QString style;
QString format;
bool rest;
bool yx;
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, bool yx) :
2018-02-25 02:31:01 +01:00
url(url), layer(layer), set(set), style(style), format(format),
rest(rest), yx(yx) {}
2018-02-25 02:31:01 +01:00
};
2018-02-20 23:37:19 +01:00
struct Zoom {
QString id;
2018-02-20 23:37:19 +01:00
qreal scaleDenominator;
QPointF topLeft;
QSize tile;
QSize matrix;
QRect limits;
Zoom() {}
Zoom(const QString &id, qreal scaleDenominator, const QPointF &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;}
2018-02-20 23:37:19 +01:00
};
2018-02-25 02:31:01 +01:00
bool load(const QString &path, const Setup &setup);
2018-02-20 23:37:19 +01:00
const QString &errorString() const {return _errorString;}
const RectC &bounds() const {return _bounds;}
QList<Zoom> zooms() const;
const Projection &projection() const {return _projection;}
2018-02-25 02:31:01 +01:00
QString tileUrl() const {return _tileUrl;}
2018-02-20 23:37:19 +01:00
static Downloader *downloader() {return _downloader;}
static void setDownloader(Downloader *downloader)
{_downloader = downloader;}
private:
struct TileMatrix {
QString id;
qreal scaleDenominator;
QPointF 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;
QXmlStreamReader reader;
QString crs;
bool layer;
bool style;
bool format;
bool set;
CTX(const Setup &setup) : setup(setup), layer(false), style(false),
format(false), set(false) {}
};
RectC wgs84BoundingBox(QXmlStreamReader &reader);
MatrixLimits tileMatrixLimits(QXmlStreamReader &reader);
TileMatrix tileMatrix(QXmlStreamReader &reader, bool yx);
QSet<MatrixLimits> tileMatrixSetLimits(QXmlStreamReader &reader);
2018-02-26 22:35:58 +01:00
QString style(QXmlStreamReader &reader);
void tileMatrixSet(CTX &ctx);
void tileMatrixSetLink(CTX &ctx);
void layer(CTX &ctx);
void contents(CTX &ctx);
void capabilities(CTX &ctx);
bool parseCapabilities(const QString &path, const Setup &setup);
2018-02-20 23:37:19 +01:00
bool getCapabilities(const QString &url, const QString &file);
2018-02-26 22:35:58 +01:00
bool createProjection(const QString &crs);
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
QString _errorString;
static Downloader *_downloader;
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