1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-03-01 21:40:48 +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), MapSource::Config::Config() : type(TMS), zooms(ZOOM_MIN, ZOOM_MAX),
bounds(Coordinates(BOUNDS_LEFT, BOUNDS_TOP), Coordinates(BOUNDS_RIGHT, bounds(Coordinates(BOUNDS_LEFT, BOUNDS_TOP), Coordinates(BOUNDS_RIGHT,
BOUNDS_BOTTOM)), style("default"), format("image/png"), rest(false), BOUNDS_BOTTOM)), format("image/png"), rest(false), yx(false) {}
yx(false) {}
Range MapSource::zooms(QXmlStreamReader &reader) Range MapSource::zooms(QXmlStreamReader &reader)
@ -195,10 +194,6 @@ Map *MapSource::loadFile(const QString &path)
_errorString = "Missing layer definition"; _errorString = "Missing layer definition";
return 0; return 0;
} }
if (config.style.isEmpty()) {
_errorString = "Missing style definiton";
return 0;
}
if (config.format.isEmpty()) { if (config.format.isEmpty()) {
_errorString = "Missing format definition"; _errorString = "Missing format definition";
return 0; return 0;

View File

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

View File

@ -64,7 +64,7 @@ private:
bool hasStyle; bool hasStyle;
bool hasCRS; 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), : name(name), style(style), isDefined(false), hasStyle(false),
hasCRS(false) {} hasCRS(false) {}
bool operator==(const Layer &other) const bool operator==(const Layer &other) const

View File

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

View File

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