1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-19 04:02:09 +01:00

Made the axis order an attribute of the set rather than a separate element

This commit is contained in:
Martin Tůma 2018-02-25 08:58:40 +01:00
parent 5e5ff6d96f
commit fbab4b0097
5 changed files with 36 additions and 37 deletions

View File

@ -126,10 +126,10 @@ Map *MapSource::map(QXmlStreamReader &reader)
{ {
QString name, url, layer, style, set; QString name, url, layer, style, set;
QString format("image/png"); QString format("image/png");
bool wmts, rest = false, invertAxis = false; bool wmts, rest = false, yx = false;
Range z(ZOOM_MIN, ZOOM_MAX); Range z(ZOOM_MIN, ZOOM_MAX);
RectC b(Coordinates(BOUNDS_LEFT, BOUNDS_TOP), RectC b(Coordinates(BOUNDS_LEFT, BOUNDS_TOP), Coordinates(BOUNDS_RIGHT,
Coordinates(BOUNDS_RIGHT, BOUNDS_BOTTOM)); BOUNDS_BOTTOM));
wmts = (reader.attributes().value("type") == "WMTS") ? true : false; wmts = (reader.attributes().value("type") == "WMTS") ? true : false;
@ -151,11 +151,10 @@ Map *MapSource::map(QXmlStreamReader &reader)
layer = reader.readElementText(); layer = reader.readElementText();
else if (reader.name() == "style") else if (reader.name() == "style")
style = reader.readElementText(); style = reader.readElementText();
else if (reader.name() == "set") else if (reader.name() == "set") {
yx = (reader.attributes().value("axis") == "yx") ? true : false;
set = reader.readElementText(); set = reader.readElementText();
else if (reader.name() == "axis") } else
invertAxis = (reader.readElementText() == "yx") ? true : false;
else
reader.skipCurrentElement(); reader.skipCurrentElement();
} }
@ -163,7 +162,7 @@ Map *MapSource::map(QXmlStreamReader &reader)
return 0; return 0;
else if (wmts) else if (wmts)
return new WMTSMap(name, WMTS::Setup(url, layer, set, style, format, return new WMTSMap(name, WMTS::Setup(url, layer, set, style, format,
rest), invertAxis); rest, yx));
else else
return new OnlineMap(name, url, z, b); return new OnlineMap(name, url, z, b);
} }

View File

@ -58,7 +58,7 @@ bool WMTS::createProjection(const QString &crs)
return false; return false;
} }
WMTS::TileMatrix WMTS::tileMatrix(QXmlStreamReader &reader) WMTS::TileMatrix WMTS::tileMatrix(QXmlStreamReader &reader, bool yx)
{ {
TileMatrix matrix; TileMatrix matrix;
@ -69,7 +69,11 @@ WMTS::TileMatrix WMTS::tileMatrix(QXmlStreamReader &reader)
matrix.scaleDenominator = reader.readElementText().toDouble(); matrix.scaleDenominator = reader.readElementText().toDouble();
else if (reader.name() == "TopLeftCorner") { else if (reader.name() == "TopLeftCorner") {
QString str = reader.readElementText(); QString str = reader.readElementText();
QTextStream(&str) >> matrix.topLeft.rx() >> matrix.topLeft.ry(); QTextStream ts(&str);
if (yx)
ts >> matrix.topLeft.ry() >> matrix.topLeft.rx();
else
ts >> matrix.topLeft.rx() >> matrix.topLeft.ry();
} else if (reader.name() == "TileWidth") } else if (reader.name() == "TileWidth")
matrix.tile.setWidth(reader.readElementText().toInt()); matrix.tile.setWidth(reader.readElementText().toInt());
else if (reader.name() == "TileHeight") else if (reader.name() == "TileHeight")
@ -88,7 +92,7 @@ WMTS::TileMatrix WMTS::tileMatrix(QXmlStreamReader &reader)
return matrix; return matrix;
} }
void WMTS::tileMatrixSet(QXmlStreamReader &reader, const QString &set) void WMTS::tileMatrixSet(QXmlStreamReader &reader, const QString &set, bool yx)
{ {
QString id, crs; QString id, crs;
QSet<TileMatrix> matrixes; QSet<TileMatrix> matrixes;
@ -99,7 +103,7 @@ void WMTS::tileMatrixSet(QXmlStreamReader &reader, const QString &set)
else if (reader.name() == "SupportedCRS") else if (reader.name() == "SupportedCRS")
crs = reader.readElementText(); crs = reader.readElementText();
else if (reader.name() == "TileMatrix") else if (reader.name() == "TileMatrix")
matrixes.insert(tileMatrix(reader)); matrixes.insert(tileMatrix(reader, yx));
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
} }
@ -219,11 +223,11 @@ void WMTS::layer(QXmlStreamReader &reader, const QString &layer,
} }
void WMTS::contents(QXmlStreamReader &reader, const QString &layer, void WMTS::contents(QXmlStreamReader &reader, const QString &layer,
const QString &set) const QString &set, bool yx)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "TileMatrixSet") if (reader.name() == "TileMatrixSet")
tileMatrixSet(reader, set); tileMatrixSet(reader, set, yx);
else if (reader.name() == "Layer") else if (reader.name() == "Layer")
WMTS::layer(reader, layer, set); WMTS::layer(reader, layer, set);
else else
@ -232,18 +236,18 @@ void WMTS::contents(QXmlStreamReader &reader, const QString &layer,
} }
void WMTS::capabilities(QXmlStreamReader &reader, const QString &layer, void WMTS::capabilities(QXmlStreamReader &reader, const QString &layer,
const QString &set) const QString &set, bool yx)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Contents") if (reader.name() == "Contents")
contents(reader, layer, set); contents(reader, layer, set, yx);
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
} }
} }
bool WMTS::parseCapabilities(const QString &path, const QString &layer, bool WMTS::parseCapabilities(const QString &path, const QString &layer,
const QString &set) const QString &set, bool yx)
{ {
QFile file(path); QFile file(path);
QXmlStreamReader reader; QXmlStreamReader reader;
@ -257,7 +261,7 @@ bool WMTS::parseCapabilities(const QString &path, const QString &layer,
if (reader.readNextStartElement()) { if (reader.readNextStartElement()) {
if (reader.name() == "Capabilities") if (reader.name() == "Capabilities")
capabilities(reader, layer, set); capabilities(reader, layer, set, yx);
else else
reader.raiseError("Not a Capabilities XML file"); reader.raiseError("Not a Capabilities XML file");
} }
@ -296,7 +300,7 @@ bool WMTS::load(const QString &file, const WMTS::Setup &setup)
if (!QFileInfo(file).exists()) if (!QFileInfo(file).exists())
if (!getCapabilities(capaUrl, file)) if (!getCapabilities(capaUrl, file))
return false; return false;
if (!parseCapabilities(file, setup.layer, setup.set)) if (!parseCapabilities(file, setup.layer, setup.set, setup.yx))
return false; return false;
if (!setup.rest) if (!setup.rest)

View File

@ -22,11 +22,12 @@ public:
QString style; QString style;
QString format; QString format;
bool rest; bool rest;
bool yx;
Setup(const QString &url, const QString &layer, const QString &set, Setup(const QString &url, const QString &layer, const QString &set,
const QString &style, const QString &format, bool rest) : const QString &style, const QString &format, bool rest, bool yx) :
url(url), layer(layer), set(set), style(style), format(format), url(url), layer(layer), set(set), style(style), format(format),
rest(rest) {} rest(rest), yx(yx) {}
}; };
struct Zoom { struct Zoom {
@ -90,18 +91,18 @@ private:
RectC wgs84BoundingBox(QXmlStreamReader &reader); RectC wgs84BoundingBox(QXmlStreamReader &reader);
MatrixLimits tileMatrixLimits(QXmlStreamReader &reader); MatrixLimits tileMatrixLimits(QXmlStreamReader &reader);
TileMatrix tileMatrix(QXmlStreamReader &reader); TileMatrix tileMatrix(QXmlStreamReader &reader, bool yx);
QSet<MatrixLimits> tileMatrixSetLimits(QXmlStreamReader &reader); QSet<MatrixLimits> tileMatrixSetLimits(QXmlStreamReader &reader);
void tileMatrixSet(QXmlStreamReader &reader, const QString &set); void tileMatrixSet(QXmlStreamReader &reader, const QString &set, bool yx);
void tileMatrixSetLink(QXmlStreamReader &reader, const QString &set); void tileMatrixSetLink(QXmlStreamReader &reader, const QString &set);
void layer(QXmlStreamReader &reader, const QString &layer, void layer(QXmlStreamReader &reader, const QString &layer,
const QString &set); const QString &set);
void contents(QXmlStreamReader &reader, const QString &layer, void contents(QXmlStreamReader &reader, const QString &layer,
const QString &set); const QString &set, bool yx);
void capabilities(QXmlStreamReader &reader, const QString &layer, void capabilities(QXmlStreamReader &reader, const QString &layer,
const QString &set); const QString &set, bool yx);
bool parseCapabilities(const QString &path, const QString &layer, bool parseCapabilities(const QString &path, const QString &layer,
const QString &set); const QString &set, bool yx);
bool getCapabilities(const QString &url, const QString &file); bool getCapabilities(const QString &url, const QString &file);
QSet<TileMatrix> _matrixes; QSet<TileMatrix> _matrixes;

View File

@ -9,9 +9,8 @@
#define CAPABILITIES_FILE "capabilities.xml" #define CAPABILITIES_FILE "capabilities.xml"
WMTSMap::WMTSMap(const QString &name, const WMTS::Setup &setup, bool invertAxis, WMTSMap::WMTSMap(const QString &name, const WMTS::Setup &setup, QObject *parent)
QObject *parent) : Map(parent), _name(name), _setup(setup), : Map(parent), _name(name), _setup(setup), _zoom(0), _valid(false)
_invertAxis(invertAxis), _zoom(0), _valid(false)
{ {
QString dir(TILES_DIR + "/" + _name); QString dir(TILES_DIR + "/" + _name);
QString file = dir + "/" + CAPABILITIES_FILE; QString file = dir + "/" + CAPABILITIES_FILE;
@ -50,13 +49,11 @@ void WMTSMap::updateTransform()
if (_projection.isGeographic()) if (_projection.isGeographic())
pixelSpan /= deg2rad(WGS84_RADIUS); pixelSpan /= deg2rad(WGS84_RADIUS);
QPointF tileSpan(z.tile.width() * pixelSpan, z.tile.height() * pixelSpan); QPointF tileSpan(z.tile.width() * pixelSpan, z.tile.height() * pixelSpan);
QPointF topLeft = _invertAxis QPointF bottomRight(z.topLeft.x() + tileSpan.x() * z.matrix.width(),
? QPointF(z.topLeft.y(), z.topLeft.x()) : z.topLeft; z.topLeft.y() - tileSpan.y() * z.matrix.height());
QPointF bottomRight(topLeft.x() + tileSpan.x() * z.matrix.width(),
topLeft.y() - tileSpan.y() * z.matrix.height());
tl.xy = QPoint(0, 0); tl.xy = QPoint(0, 0);
tl.pp = topLeft; tl.pp = z.topLeft;
br.xy = QPoint(z.tile.width() * z.matrix.width(), br.xy = QPoint(z.tile.width() * z.matrix.width(),
z.tile.height() * z.matrix.height()); z.tile.height() * z.matrix.height());
br.pp = bottomRight; br.pp = bottomRight;

View File

@ -13,8 +13,7 @@ class WMTSMap : public Map
Q_OBJECT Q_OBJECT
public: public:
WMTSMap(const QString &name, const WMTS::Setup &setup, bool invertAxis, WMTSMap(const QString &name, const WMTS::Setup &setup, QObject *parent = 0);
QObject *parent = 0);
const QString &name() const {return _name;} const QString &name() const {return _name;}
@ -58,7 +57,6 @@ private:
TileLoader _tileLoader; TileLoader _tileLoader;
RectC _bounds; RectC _bounds;
QList<WMTS::Zoom> _zooms; QList<WMTS::Zoom> _zooms;
bool _invertAxis;
Projection _projection; Projection _projection;
QTransform _transform, _inverted; QTransform _transform, _inverted;
int _zoom; int _zoom;