From 9859608115898efa50f2408f5bd2d4d21bf5072a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Wed, 4 Mar 2020 19:47:23 +0100 Subject: [PATCH] Added missing support for URLs defined in OnlineResources --- src/map/wms.cpp | 38 +++++++++++++++++++++++++++++++++++++- src/map/wms.h | 6 ++++++ src/map/wmsmap.cpp | 6 +++--- src/map/wmsmap.h | 2 +- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/map/wms.cpp b/src/map/wms.cpp index e3329a86..7d5f0c76 100644 --- a/src/map/wms.cpp +++ b/src/map/wms.cpp @@ -38,6 +38,38 @@ WMS::CTX::CTX(const Setup &setup) : setup(setup), formatSupported(false) } } +void WMS::get(QXmlStreamReader &reader, CTX &ctx) +{ + while (reader.readNextStartElement()) { + if (reader.name() == "OnlineResource") { + QXmlStreamAttributes attr = reader.attributes(); + ctx.url = attr.value("xlink:href").toString(); + reader.skipCurrentElement(); + } else + reader.skipCurrentElement(); + } +} + +void WMS::http(QXmlStreamReader &reader, CTX &ctx) +{ + while (reader.readNextStartElement()) { + if (reader.name() == "Get") + get(reader, ctx); + else + reader.skipCurrentElement(); + } +} + +void WMS::dcpType(QXmlStreamReader &reader, CTX &ctx) +{ + while (reader.readNextStartElement()) { + if (reader.name() == "HTTP") + http(reader, ctx); + else + reader.skipCurrentElement(); + } +} + void WMS::getMap(QXmlStreamReader &reader, CTX &ctx) { while (reader.readNextStartElement()) { @@ -45,7 +77,9 @@ void WMS::getMap(QXmlStreamReader &reader, CTX &ctx) QString format(reader.readElementText()); if (bareFormat(format) == bareFormat(ctx.setup.format())) ctx.formatSupported = true; - } else + } else if (reader.name() == "DCPType") + dcpType(reader, ctx); + else reader.skipCurrentElement(); } } @@ -272,6 +306,8 @@ bool WMS::parseCapabilities(const QString &path, const Setup &setup) return false; } + _tileUrl = ctx.url.isEmpty() ? setup.url() : ctx.url; + return true; } diff --git a/src/map/wms.h b/src/map/wms.h index ccab0fe4..63bea256 100644 --- a/src/map/wms.h +++ b/src/map/wms.h @@ -54,6 +54,7 @@ public: const RangeF &scaleDenominator() const {return _scaleDenominator;} const RectC &boundingBox() const {return _boundingBox;} const QString &version() const {return _version;} + const QString &tileUrl() const {return _tileUrl;} bool isValid() const {return _valid;} const QString &errorString() const {return _errorString;} @@ -79,12 +80,16 @@ private: const Setup &setup; QList layers; bool formatSupported; + QString url; CTX(const Setup &setup); }; RectC geographicBoundingBox(QXmlStreamReader &reader); QString style(QXmlStreamReader &reader); + void get(QXmlStreamReader &reader, CTX &ctx); + void http(QXmlStreamReader &reader, CTX &ctx); + void dcpType(QXmlStreamReader &reader, CTX &ctx); void getMap(QXmlStreamReader &reader, CTX &ctx); void request(QXmlStreamReader &reader, CTX &ctx); void layer(QXmlStreamReader &reader, CTX &ctx, const QList &pCRSs, @@ -100,6 +105,7 @@ private: RangeF _scaleDenominator; RectC _boundingBox; QString _version; + QString _tileUrl; bool _valid; QString _errorString; diff --git a/src/map/wmsmap.cpp b/src/map/wmsmap.cpp index 7a69243d..dbb606c6 100644 --- a/src/map/wmsmap.cpp +++ b/src/map/wmsmap.cpp @@ -17,13 +17,13 @@ double WMSMap::sd2res(double scaleDenominator) const return scaleDenominator * 0.28e-3 * _projection.units().fromMeters(1.0); } -QString WMSMap::tileUrl(const QString &version) const +QString WMSMap::tileUrl(const QString &baseUrl, const QString &version) const { QString url; url = QString("%1%2service=WMS&version=%3&request=GetMap&bbox=$bbox" "&width=%4&height=%5&layers=%6&styles=%7&format=%8&transparent=true") - .arg(_setup.url(), _setup.url().contains('?') ? "&" : "?", version, + .arg(baseUrl, baseUrl.contains('?') ? "&" : "?", version, QString::number(_tileSize), QString::number(_tileSize), _setup.layer(), _setup.style(), _setup.format()); @@ -83,7 +83,7 @@ bool WMSMap::loadWMS() _projection = wms.projection(); _bbox = wms.boundingBox(); _bounds = RectD(_bbox, _projection); - _tileLoader->setUrl(tileUrl(wms.version())); + _tileLoader->setUrl(tileUrl(wms.tileUrl(), wms.version())); if (wms.version() >= "1.3.0") { if (_setup.coordinateSystem().axisOrder() == CoordinateSystem::Unknown) diff --git a/src/map/wmsmap.h b/src/map/wmsmap.h index 12060de1..367f219a 100644 --- a/src/map/wmsmap.h +++ b/src/map/wmsmap.h @@ -40,7 +40,7 @@ public: QString errorString() const {return _errorString;} private: - QString tileUrl(const QString &version) const; + QString tileUrl(const QString &baseUrl, const QString &version) const; double sd2res(double scaleDenominator) const; QString tilesDir() const; void computeZooms(const RangeF &scaleDenominator);