1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Added support for WMS 1.1.x versions

This commit is contained in:
Martin Tůma 2018-03-31 11:27:01 +02:00
parent aecda0e517
commit 16f2d7ad34
4 changed files with 25 additions and 20 deletions

View File

@ -67,18 +67,11 @@ void WMS::layer(QXmlStreamReader &reader, CTX &ctx,
else if (reader.name() == "BoundingBox") { else if (reader.name() == "BoundingBox") {
QXmlStreamAttributes attr = reader.attributes(); QXmlStreamAttributes attr = reader.attributes();
if (attr.value("CRS") == ctx.setup.crs()) { if (attr.value("CRS") == ctx.setup.crs()) {
if (ctx.setup.yx()) boundingBox = QRectF(QPointF(
boundingBox = QRectF(QPointF( attr.value("minx").toString().toDouble(),
attr.value("miny").toString().toDouble(), attr.value("maxy").toString().toDouble()),
attr.value("maxx").toString().toDouble()), QPointF(attr.value("maxx").toString().toDouble(),
QPointF(attr.value("maxy").toString().toDouble(), attr.value("miny").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()));
} }
reader.skipCurrentElement(); reader.skipCurrentElement();
} else if (reader.name() == "Layer") } else if (reader.name() == "Layer")
@ -113,6 +106,8 @@ void WMS::capability(QXmlStreamReader &reader, CTX &ctx)
void WMS::capabilities(QXmlStreamReader &reader, CTX &ctx) void WMS::capabilities(QXmlStreamReader &reader, CTX &ctx)
{ {
_version = reader.attributes().value("version").toString();
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Capability") if (reader.name() == "Capability")
capability(reader, ctx); capability(reader, ctx);

View File

@ -42,6 +42,7 @@ public:
const Projection &projection() const {return _projection;} const Projection &projection() const {return _projection;}
const RangeF &scaleDenominator() const {return _scaleDenominator;} const RangeF &scaleDenominator() const {return _scaleDenominator;}
const QRectF &boundingBox() const {return _boundingBox;} const QRectF &boundingBox() const {return _boundingBox;}
const QString &version() const {return _version;}
bool isValid() const {return _valid;} bool isValid() const {return _valid;}
const QString &errorString() const {return _errorString;} const QString &errorString() const {return _errorString;}
@ -76,6 +77,7 @@ private:
Projection _projection; Projection _projection;
RangeF _scaleDenominator; RangeF _scaleDenominator;
QRectF _boundingBox; QRectF _boundingBox;
QString _version;
bool _valid; bool _valid;
QString _errorString; QString _errorString;

View File

@ -15,11 +15,15 @@ qreal WMSMap::sd2res(qreal scaleDenominator) const
return scaleDenominator * 0.28e-3 * _projection.units().fromMeters(1.0); 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" QString crs = version >= "1.3.0"
"&width=%3&height=%4&layers=%5&styles=%6&format=%7&transparent=true") ? QString("CRS=%1").arg(_setup.crs())
.arg(_setup.url(), _setup.crs(), QString::number(TILE_SIZE), : 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(), QString::number(TILE_SIZE), _setup.layer(), _setup.style(),
_setup.format()); _setup.format());
} }
@ -74,9 +78,12 @@ bool WMSMap::loadWMS()
return false; return false;
} }
_yx = (_setup.yx() && wms.version() >= "1.3.0") ? true : false;
_projection = wms.projection(); _projection = wms.projection();
_boundingBox = wms.boundingBox(); _boundingBox = _yx ? QRectF(QPointF(wms.boundingBox().bottom(),
_tileLoader = TileLoader(tileUrl(), tilesDir()); wms.boundingBox().right()), QPointF(wms.boundingBox().top(),
wms.boundingBox().left())) : wms.boundingBox();
_tileLoader = TileLoader(tileUrl(wms.version()), tilesDir());
computeZooms(wms.scaleDenominator()); computeZooms(wms.scaleDenominator());
updateTransform(); updateTransform();
@ -205,7 +212,7 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect)
j * TILE_SIZE))); j * TILE_SIZE)));
QPointF tbr(_transform.img2proj(QPointF(i * TILE_SIZE + TILE_SIZE QPointF tbr(_transform.img2proj(QPointF(i * TILE_SIZE + TILE_SIZE
- 1, j * TILE_SIZE + TILE_SIZE - 1))); - 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(QPointF(tbr.y(), tbr.x()), QPointF(ttl.y(), ttl.x()))
: QRectF(ttl, tbr); : QRectF(ttl, tbr);

View File

@ -45,7 +45,7 @@ private slots:
void emitLoaded(); void emitLoaded();
private: private:
QString tileUrl() const; QString tileUrl(const QString &version) const;
qreal sd2res(qreal scaleDenominator) const; qreal sd2res(qreal scaleDenominator) const;
QString tilesDir() const; QString tilesDir() const;
void computeZooms(const RangeF &scaleDenominator); void computeZooms(const RangeF &scaleDenominator);
@ -64,6 +64,7 @@ private:
QVector<qreal> _zooms; QVector<qreal> _zooms;
int _zoom; int _zoom;
QRectF _boundingBox; QRectF _boundingBox;
bool _yx;
bool _block; bool _block;
bool _valid; bool _valid;