From 8132ff722d48bf20f06c7ad7dd2735bb10e60e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 11 Mar 2018 10:31:41 +0100 Subject: [PATCH] Added support for WMTS dimensions --- src/map/mapsource.cpp | 9 ++++++++- src/map/mapsource.h | 1 + src/map/wmts.cpp | 12 ++++++++++-- src/map/wmts.h | 6 ++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/map/mapsource.cpp b/src/map/mapsource.cpp index 398c959f..93e3327e 100644 --- a/src/map/mapsource.cpp +++ b/src/map/mapsource.cpp @@ -153,6 +153,13 @@ void MapSource::map(QXmlStreamReader &reader, Config &config) config.wmts.yx = (reader.attributes().value("axis") == "yx") ? true : false; config.wmts.set = reader.readElementText(); + } else if (reader.name() == "dimension") { + QXmlStreamAttributes attr = reader.attributes(); + if (!attr.hasAttribute("id")) + reader.raiseError("Missing dimension id"); + else + config.wmts.dimensions.append(QPair( + attr.value("id").toString(), reader.readElementText())); } else reader.skipCurrentElement(); } @@ -213,7 +220,7 @@ Map *MapSource::loadFile(const QString &path) if (config.type == WMTS) m = new WMTSMap(config.name, WMTS::Setup(config.url, config.wmts.layer, config.wmts.set, config.wmts.style, config.wmts.format, - config.wmts.rest, config.wmts.yx)); + config.wmts.rest, config.wmts.yx, config.wmts.dimensions)); else m = new OnlineMap(config.name, config.url, config.tms.zooms, config.tms.bounds); diff --git a/src/map/mapsource.h b/src/map/mapsource.h index 7797615d..82c92486 100644 --- a/src/map/mapsource.h +++ b/src/map/mapsource.h @@ -34,6 +34,7 @@ private: QString format; bool rest; bool yx; + QList > dimensions; WMTSConfig() : format("image/png"), rest(false), yx(false) {} }; diff --git a/src/map/wmts.cpp b/src/map/wmts.cpp index e8723709..38f40f94 100644 --- a/src/map/wmts.cpp +++ b/src/map/wmts.cpp @@ -357,17 +357,25 @@ bool WMTS::load(const QString &file, const WMTS::Setup &setup) if (!parseCapabilities(file, setup)) return false; - if (!setup.rest) + if (!setup.rest) { _tileUrl = QString("%1?service=WMTS&Version=1.0.0&request=GetTile" "&Format=%2&Layer=%3&Style=%4&TileMatrixSet=%5&TileMatrix=$z" "&TileRow=$y&TileCol=$x").arg(setup.url).arg(setup.format) .arg(setup.layer).arg(setup.style).arg(setup.set); - else { + for (int i = 0; i < setup.dimensions.size(); i++) { + const QPair &dim = setup.dimensions.at(i); + _tileUrl.append(QString("&%1=%2").arg(dim.first).arg(dim.second)); + } + } else { _tileUrl.replace("{Style}", setup.style); _tileUrl.replace("{TileMatrixSet}", setup.set); _tileUrl.replace("{TileMatrix}", "$z"); _tileUrl.replace("{TileRow}", "$y"); _tileUrl.replace("{TileCol}", "$x"); + for (int i = 0; i < setup.dimensions.size(); i++) { + const QPair &dim = setup.dimensions.at(i); + _tileUrl.replace(QString("{%1}").arg(dim.first), dim.second); + } } return true; diff --git a/src/map/wmts.h b/src/map/wmts.h index 0e0c5d52..2fa413d4 100644 --- a/src/map/wmts.h +++ b/src/map/wmts.h @@ -23,11 +23,13 @@ public: QString format; bool rest; bool yx; + QList > dimensions; Setup(const QString &url, const QString &layer, const QString &set, - const QString &style, const QString &format, bool rest, bool yx) : + const QString &style, const QString &format, bool rest, bool yx, + const QList > &dimensions) : url(url), layer(layer), set(set), style(style), format(format), - rest(rest), yx(yx) {} + rest(rest), yx(yx), dimensions(dimensions) {} }; struct Zoom {