1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Improved default WMS/WMTS style handling

This commit is contained in:
Martin Tůma 2018-04-03 22:35:13 +02:00
parent 68eac5b8cc
commit 4096d87a6a
5 changed files with 36 additions and 37 deletions

View File

@ -15,8 +15,7 @@
MapSource::Config::Config() : type(TMS), zooms(ZOOM_MIN, ZOOM_MAX),
bounds(Coordinates(BOUNDS_LEFT, BOUNDS_TOP), Coordinates(BOUNDS_RIGHT,
BOUNDS_BOTTOM)), style("default"), format("image/png"), rest(false),
yx(false) {}
BOUNDS_BOTTOM)), format("image/png"), rest(false), yx(false) {}
Range MapSource::zooms(QXmlStreamReader &reader)
@ -195,10 +194,6 @@ Map *MapSource::loadFile(const QString &path)
_errorString = "Missing layer definition";
return 0;
}
if (config.style.isEmpty()) {
_errorString = "Missing style definiton";
return 0;
}
if (config.format.isEmpty()) {
_errorString = "Missing format definition";
return 0;

View File

@ -12,14 +12,19 @@ Downloader *WMS::_downloader = 0;
WMS::CTX::CTX(const Setup &setup) : setup(setup), formatSupported(false)
{
QStringList ll = setup.layer().split(',');
QStringList sl = setup.style().split(',');
if (setup.style().isEmpty()) {
for (int i = 0; i < ll.size(); i++)
layers.append(Layer(ll.at(i)));
} else {
QStringList sl = setup.style().split(',');
if (ll.size() != sl.size())
return;
for (int i = 0; i < ll.size(); i++)
layers.append(Layer(ll.at(i), sl.at(i)));
}
}
void WMS::getMap(QXmlStreamReader &reader, CTX &ctx)
{
@ -123,7 +128,7 @@ void WMS::layer(QXmlStreamReader &reader, CTX &ctx,
layer.scaleDenominator = scaleDenominator;
layer.boundingBox = boundingBox;
layer.isDefined = true;
layer.hasStyle = styles.contains(layer.style);
layer.hasStyle = styles.contains(layer.style) || layer.style.isEmpty();
layer.hasCRS = CRSs.contains(ctx.setup.crs());
}
}
@ -135,8 +140,6 @@ void WMS::capability(QXmlStreamReader &reader, CTX &ctx)
RangeF scaleDenominator(2132.729583849784, 559082264.0287178);
RectC boundingBox;
styles.append("default");
while (reader.readNextStartElement()) {
if (reader.name() == "Layer")
layer(reader, ctx, CRSs, styles, scaleDenominator, boundingBox);
@ -167,7 +170,7 @@ bool WMS::parseCapabilities(const QString &path, const Setup &setup)
if (ctx.layers.isEmpty()) {
_errorString = "Invalid layers definition";
_errorString = "Invalid layers/styles list definition";
return false;
}

View File

@ -64,7 +64,7 @@ private:
bool hasStyle;
bool hasCRS;
Layer(const QString &name, const QString &style = "default")
Layer(const QString &name, const QString &style = QString())
: name(name), style(style), isDefined(false), hasStyle(false),
hasCRS(false) {}
bool operator==(const Layer &other) const

View File

@ -124,7 +124,7 @@ void WMTS::tileMatrixSetLink(QXmlStreamReader &reader, CTX &ctx)
}
if (id == ctx.setup.set()) {
ctx.set = true;
ctx.hasSet = true;
_limits = limits;
}
}
@ -188,14 +188,14 @@ void WMTS::layer(QXmlStreamReader &reader, CTX &ctx)
}
if (id == ctx.setup.layer()) {
ctx.layer = true;
ctx.hasLayer = true;
_bounds = bounds;
if (ctx.setup.rest())
_tileUrl = tpl;
if (styles.contains(ctx.setup.style()))
ctx.style = true;
if (styles.contains(ctx.setup.style()) || ctx.setup.style().isEmpty())
ctx.hasStyle = true;
if (formats.contains(ctx.setup.format()))
ctx.format = true;
ctx.hasFormat = true;
}
}
@ -245,19 +245,19 @@ bool WMTS::parseCapabilities(const QString &path, const Setup &setup)
return false;
}
if (!ctx.layer) {
if (!ctx.hasLayer) {
_errorString = ctx.setup.layer() + ": layer not provided";
return false;
}
if (!ctx.style) {
if (!ctx.hasStyle) {
_errorString = ctx.setup.style() + ": style not provided";
return false;
}
if (!ctx.setup.rest() && !ctx.format) {
if (!ctx.setup.rest() && !ctx.hasFormat) {
_errorString = ctx.setup.format() + ": format not provided";
return false;
}
if (!ctx.set) {
if (!ctx.hasSet) {
_errorString = ctx.setup.set() + ": set not provided";
return false;
}
@ -314,17 +314,18 @@ WMTS::WMTS(const QString &file, const WMTS::Setup &setup) : _valid(false)
if (!parseCapabilities(file, setup))
return;
QString style = setup.style().isEmpty() ? "default" : setup.style();
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());
"&TileRow=$y&TileCol=$x").arg(setup.url(), setup.format(),
setup.layer(), style, setup.set());
for (int i = 0; i < setup.dimensions().size(); i++) {
const QPair<QString, QString> &dim = setup.dimensions().at(i);
_tileUrl.append(QString("&%1=%2").arg(dim.first).arg(dim.second));
_tileUrl.append(QString("&%1=%2").arg(dim.first, dim.second));
}
} else {
_tileUrl.replace("{Style}", setup.style(), Qt::CaseInsensitive);
_tileUrl.replace("{Style}", style, Qt::CaseInsensitive);
_tileUrl.replace("{TileMatrixSet}", setup.set(), Qt::CaseInsensitive);
_tileUrl.replace("{TileMatrix}", "$z", Qt::CaseInsensitive);
_tileUrl.replace("{TileRow}", "$y", Qt::CaseInsensitive);
@ -350,8 +351,8 @@ QList<WMTS::Zoom> WMTS::zooms() const
zooms.append(Zoom(mi->id, mi->scaleDenominator, mi->topLeft,
mi->tile, mi->matrix, QRect()));
else
zooms.append(Zoom(Zoom(mi->id, mi->scaleDenominator, mi->topLeft,
mi->tile, mi->matrix, li->rect)));
zooms.append(Zoom(mi->id, mi->scaleDenominator, mi->topLeft,
mi->tile, mi->matrix, li->rect));
}
qSort(zooms);

View File

@ -120,13 +120,13 @@ private:
struct CTX {
const Setup &setup;
QString crs;
bool layer;
bool style;
bool format;
bool set;
bool hasLayer;
bool hasStyle;
bool hasFormat;
bool hasSet;
CTX(const Setup &setup) : setup(setup), layer(false), style(false),
format(false), set(false) {}
CTX(const Setup &setup) : setup(setup), hasLayer(false), hasStyle(false),
hasFormat(false), hasSet(false) {}
};
RectC wgs84BoundingBox(QXmlStreamReader &reader);