From 16f2d7ad349ed334a73412df19a527aaaef92e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sat, 31 Mar 2018 11:27:01 +0200 Subject: [PATCH] Added support for WMS 1.1.x versions --- src/map/wms.cpp | 19 +++++++------------ src/map/wms.h | 2 ++ src/map/wmsmap.cpp | 21 ++++++++++++++------- src/map/wmsmap.h | 3 ++- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/map/wms.cpp b/src/map/wms.cpp index c7b0a798..75246889 100644 --- a/src/map/wms.cpp +++ b/src/map/wms.cpp @@ -67,18 +67,11 @@ void WMS::layer(QXmlStreamReader &reader, CTX &ctx, else if (reader.name() == "BoundingBox") { QXmlStreamAttributes attr = reader.attributes(); if (attr.value("CRS") == ctx.setup.crs()) { - if (ctx.setup.yx()) - boundingBox = QRectF(QPointF( - attr.value("miny").toString().toDouble(), - attr.value("maxx").toString().toDouble()), - QPointF(attr.value("maxy").toString().toDouble(), - attr.value("minx").toString().toDouble())); - else - boundingBox = QRectF(QPointF( - attr.value("minx").toString().toDouble(), - attr.value("maxy").toString().toDouble()), - QPointF(attr.value("maxx").toString().toDouble(), - attr.value("miny").toString().toDouble())); + boundingBox = QRectF(QPointF( + attr.value("minx").toString().toDouble(), + attr.value("maxy").toString().toDouble()), + QPointF(attr.value("maxx").toString().toDouble(), + attr.value("miny").toString().toDouble())); } reader.skipCurrentElement(); } else if (reader.name() == "Layer") @@ -113,6 +106,8 @@ void WMS::capability(QXmlStreamReader &reader, CTX &ctx) void WMS::capabilities(QXmlStreamReader &reader, CTX &ctx) { + _version = reader.attributes().value("version").toString(); + while (reader.readNextStartElement()) { if (reader.name() == "Capability") capability(reader, ctx); diff --git a/src/map/wms.h b/src/map/wms.h index 90e2f9d0..27cfc508 100644 --- a/src/map/wms.h +++ b/src/map/wms.h @@ -42,6 +42,7 @@ public: const Projection &projection() const {return _projection;} const RangeF &scaleDenominator() const {return _scaleDenominator;} const QRectF &boundingBox() const {return _boundingBox;} + const QString &version() const {return _version;} bool isValid() const {return _valid;} const QString &errorString() const {return _errorString;} @@ -76,6 +77,7 @@ private: Projection _projection; RangeF _scaleDenominator; QRectF _boundingBox; + QString _version; bool _valid; QString _errorString; diff --git a/src/map/wmsmap.cpp b/src/map/wmsmap.cpp index 302863ee..6064ef4b 100644 --- a/src/map/wmsmap.cpp +++ b/src/map/wmsmap.cpp @@ -15,11 +15,15 @@ qreal WMSMap::sd2res(qreal scaleDenominator) const return scaleDenominator * 0.28e-3 * _projection.units().fromMeters(1.0); } -QString WMSMap::tileUrl() const +QString WMSMap::tileUrl(const QString &version) const { - return QString("%1?version=1.3.0&request=GetMap&CRS=%2&bbox=$bbox" - "&width=%3&height=%4&layers=%5&styles=%6&format=%7&transparent=true") - .arg(_setup.url(), _setup.crs(), QString::number(TILE_SIZE), + QString crs = version >= "1.3.0" + ? QString("CRS=%1").arg(_setup.crs()) + : QString("SRS=%1").arg(_setup.crs()); + + return QString("%1?version=%2&request=GetMap&%3&bbox=$bbox" + "&width=%4&height=%5&layers=%6&styles=%7&format=%8&transparent=true") + .arg(_setup.url(), version, crs, QString::number(TILE_SIZE), QString::number(TILE_SIZE), _setup.layer(), _setup.style(), _setup.format()); } @@ -74,9 +78,12 @@ bool WMSMap::loadWMS() return false; } + _yx = (_setup.yx() && wms.version() >= "1.3.0") ? true : false; _projection = wms.projection(); - _boundingBox = wms.boundingBox(); - _tileLoader = TileLoader(tileUrl(), tilesDir()); + _boundingBox = _yx ? QRectF(QPointF(wms.boundingBox().bottom(), + wms.boundingBox().right()), QPointF(wms.boundingBox().top(), + wms.boundingBox().left())) : wms.boundingBox(); + _tileLoader = TileLoader(tileUrl(wms.version()), tilesDir()); computeZooms(wms.scaleDenominator()); updateTransform(); @@ -205,7 +212,7 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect) j * TILE_SIZE))); QPointF tbr(_transform.img2proj(QPointF(i * TILE_SIZE + TILE_SIZE - 1, j * TILE_SIZE + TILE_SIZE - 1))); - QRectF bbox = _setup.yx() + QRectF bbox = _yx ? QRectF(QPointF(tbr.y(), tbr.x()), QPointF(ttl.y(), ttl.x())) : QRectF(ttl, tbr); diff --git a/src/map/wmsmap.h b/src/map/wmsmap.h index 3c90aa59..db41d79a 100644 --- a/src/map/wmsmap.h +++ b/src/map/wmsmap.h @@ -45,7 +45,7 @@ private slots: void emitLoaded(); private: - QString tileUrl() const; + QString tileUrl(const QString &version) const; qreal sd2res(qreal scaleDenominator) const; QString tilesDir() const; void computeZooms(const RangeF &scaleDenominator); @@ -64,6 +64,7 @@ private: QVector _zooms; int _zoom; QRectF _boundingBox; + bool _yx; bool _block; bool _valid;