2018-02-20 23:37:19 +01:00
|
|
|
#include <QXmlStreamReader>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QEventLoop>
|
|
|
|
#include <QTextStream>
|
2018-02-21 00:13:11 +01:00
|
|
|
#include <QStringList>
|
2018-02-24 10:34:27 +01:00
|
|
|
#include <QtAlgorithms>
|
2018-02-27 21:50:29 +01:00
|
|
|
#include <QXmlStreamReader>
|
2018-02-20 23:37:19 +01:00
|
|
|
#include "downloader.h"
|
|
|
|
#include "pcs.h"
|
2018-03-30 10:25:05 +02:00
|
|
|
#include "crs.h"
|
2018-02-20 23:37:19 +01:00
|
|
|
#include "wmts.h"
|
|
|
|
|
|
|
|
|
2020-03-03 09:29:16 +01:00
|
|
|
static QString bareFormat(const QString &format)
|
|
|
|
{
|
|
|
|
return format.left(format.indexOf(';')).trimmed();
|
|
|
|
}
|
|
|
|
|
2018-10-15 00:20:20 +02:00
|
|
|
static void skipParentElement(QXmlStreamReader &reader)
|
|
|
|
{
|
|
|
|
while (reader.readNextStartElement())
|
|
|
|
reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:38:23 +02:00
|
|
|
WMTS::TileMatrix WMTS::tileMatrix(QXmlStreamReader &reader)
|
2018-02-20 23:37:19 +01:00
|
|
|
{
|
2018-02-24 16:44:30 +01:00
|
|
|
TileMatrix matrix;
|
2018-02-20 23:37:19 +01:00
|
|
|
|
|
|
|
while (reader.readNextStartElement()) {
|
2020-12-22 22:09:09 +01:00
|
|
|
if (reader.name() == QLatin1String("Identifier"))
|
2018-02-24 16:44:30 +01:00
|
|
|
matrix.id = reader.readElementText();
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("ScaleDenominator"))
|
2018-02-24 16:44:30 +01:00
|
|
|
matrix.scaleDenominator = reader.readElementText().toDouble();
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("TopLeftCorner")) {
|
2018-02-20 23:37:19 +01:00
|
|
|
QString str = reader.readElementText();
|
2018-02-25 08:58:40 +01:00
|
|
|
QTextStream ts(&str);
|
2018-04-05 20:38:23 +02:00
|
|
|
ts >> matrix.topLeft.rx() >> matrix.topLeft.ry();
|
2020-12-22 22:09:09 +01:00
|
|
|
} else if (reader.name() == QLatin1String("TileWidth"))
|
2018-02-24 16:44:30 +01:00
|
|
|
matrix.tile.setWidth(reader.readElementText().toInt());
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("TileHeight"))
|
2018-02-24 16:44:30 +01:00
|
|
|
matrix.tile.setHeight(reader.readElementText().toInt());
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("MatrixWidth"))
|
2018-02-24 16:44:30 +01:00
|
|
|
matrix.matrix.setWidth(reader.readElementText().toInt());
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("MatrixHeight"))
|
2018-02-24 16:44:30 +01:00
|
|
|
matrix.matrix.setHeight(reader.readElementText().toInt());
|
2018-02-20 23:37:19 +01:00
|
|
|
else
|
|
|
|
reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
|
2018-02-24 16:44:30 +01:00
|
|
|
if (!matrix.isValid())
|
|
|
|
reader.raiseError("Invalid TileMatrix definition");
|
|
|
|
|
|
|
|
return matrix;
|
2018-02-20 23:37:19 +01:00
|
|
|
}
|
|
|
|
|
2018-02-27 21:50:29 +01:00
|
|
|
void WMTS::tileMatrixSet(QXmlStreamReader &reader, CTX &ctx)
|
2018-02-20 23:37:19 +01:00
|
|
|
{
|
2018-02-27 21:50:29 +01:00
|
|
|
while (reader.readNextStartElement()) {
|
2020-12-22 22:09:09 +01:00
|
|
|
if (reader.name() == QLatin1String("Identifier")) {
|
2020-03-17 21:06:51 +01:00
|
|
|
if (reader.readElementText() != _setup.set()) {
|
2018-10-15 00:20:20 +02:00
|
|
|
skipParentElement(reader);
|
|
|
|
return;
|
|
|
|
}
|
2020-12-22 22:09:09 +01:00
|
|
|
} else if (reader.name() == QLatin1String("SupportedCRS"))
|
2018-10-15 00:20:20 +02:00
|
|
|
ctx.crs = reader.readElementText();
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("TileMatrix"))
|
2018-10-15 00:20:20 +02:00
|
|
|
ctx.matrixes.insert(tileMatrix(reader));
|
2018-02-20 23:37:19 +01:00
|
|
|
else
|
2018-02-27 21:50:29 +01:00
|
|
|
reader.skipCurrentElement();
|
2018-02-20 23:37:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-24 16:44:30 +01:00
|
|
|
WMTS::MatrixLimits WMTS::tileMatrixLimits(QXmlStreamReader &reader)
|
2018-02-24 01:59:03 +01:00
|
|
|
{
|
2018-02-24 16:44:30 +01:00
|
|
|
MatrixLimits limits;
|
2018-02-24 01:59:03 +01:00
|
|
|
|
|
|
|
while (reader.readNextStartElement()) {
|
2020-12-22 22:09:09 +01:00
|
|
|
if (reader.name() == QLatin1String("TileMatrix"))
|
2018-02-24 16:44:30 +01:00
|
|
|
limits.id = reader.readElementText();
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("MinTileRow"))
|
2018-02-24 16:44:30 +01:00
|
|
|
limits.rect.setTop(reader.readElementText().toInt());
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("MaxTileRow"))
|
2018-02-24 16:44:30 +01:00
|
|
|
limits.rect.setBottom(reader.readElementText().toInt());
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("MinTileCol"))
|
2018-02-24 16:44:30 +01:00
|
|
|
limits.rect.setLeft(reader.readElementText().toInt());
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("MaxTileCol"))
|
2018-02-24 16:44:30 +01:00
|
|
|
limits.rect.setRight(reader.readElementText().toInt());
|
2018-02-24 01:59:03 +01:00
|
|
|
else
|
|
|
|
reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
|
2018-02-24 16:44:30 +01:00
|
|
|
if (!limits.isValid())
|
|
|
|
reader.raiseError("Invalid TileMatrixLimits definition");
|
|
|
|
|
|
|
|
return limits;
|
2018-02-24 01:59:03 +01:00
|
|
|
}
|
|
|
|
|
2018-02-24 16:44:30 +01:00
|
|
|
QSet<WMTS::MatrixLimits> WMTS::tileMatrixSetLimits(QXmlStreamReader &reader)
|
2018-02-24 01:59:03 +01:00
|
|
|
{
|
2018-02-24 16:44:30 +01:00
|
|
|
QSet<MatrixLimits> limits;
|
|
|
|
|
2018-02-24 01:59:03 +01:00
|
|
|
while (reader.readNextStartElement()) {
|
2020-12-22 22:09:09 +01:00
|
|
|
if (reader.name() == QLatin1String("TileMatrixLimits"))
|
2018-02-24 16:44:30 +01:00
|
|
|
limits.insert(tileMatrixLimits(reader));
|
2018-02-24 01:59:03 +01:00
|
|
|
else
|
|
|
|
reader.skipCurrentElement();
|
|
|
|
}
|
2018-02-24 16:44:30 +01:00
|
|
|
|
|
|
|
return limits;
|
2018-02-24 01:59:03 +01:00
|
|
|
}
|
|
|
|
|
2018-02-27 21:50:29 +01:00
|
|
|
void WMTS::tileMatrixSetLink(QXmlStreamReader &reader, CTX &ctx)
|
2018-02-24 01:59:03 +01:00
|
|
|
{
|
2018-02-27 21:50:29 +01:00
|
|
|
while (reader.readNextStartElement()) {
|
2020-12-22 22:09:09 +01:00
|
|
|
if (reader.name() == QLatin1String("TileMatrixSet")) {
|
2020-03-17 21:06:51 +01:00
|
|
|
if (reader.readElementText() == _setup.set())
|
2018-10-15 00:20:20 +02:00
|
|
|
ctx.hasSet = true;
|
|
|
|
else {
|
|
|
|
skipParentElement(reader);
|
|
|
|
return;
|
|
|
|
}
|
2020-12-22 22:09:09 +01:00
|
|
|
} else if (reader.name() == QLatin1String("TileMatrixSetLimits"))
|
2018-10-15 00:20:20 +02:00
|
|
|
ctx.limits = tileMatrixSetLimits(reader);
|
2018-02-24 01:59:03 +01:00
|
|
|
else
|
2018-02-27 21:50:29 +01:00
|
|
|
reader.skipCurrentElement();
|
2018-02-24 01:59:03 +01:00
|
|
|
}
|
2018-02-24 16:44:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
RectC WMTS::wgs84BoundingBox(QXmlStreamReader &reader)
|
|
|
|
{
|
|
|
|
Coordinates topLeft, bottomRight;
|
|
|
|
|
|
|
|
while (reader.readNextStartElement()) {
|
2020-12-22 22:09:09 +01:00
|
|
|
if (reader.name() == QLatin1String("LowerCorner")) {
|
2018-02-24 16:44:30 +01:00
|
|
|
QString str = reader.readElementText();
|
|
|
|
QTextStream(&str) >> topLeft.rlon() >> bottomRight.rlat();
|
2020-12-22 22:09:09 +01:00
|
|
|
} else if (reader.name() == QLatin1String("UpperCorner")) {
|
2018-02-24 16:44:30 +01:00
|
|
|
QString str = reader.readElementText();
|
|
|
|
QTextStream(&str) >> bottomRight.rlon() >> topLeft.rlat();
|
|
|
|
} else
|
|
|
|
reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
return RectC(topLeft, bottomRight);
|
2018-02-24 01:59:03 +01:00
|
|
|
}
|
|
|
|
|
2018-02-26 22:35:58 +01:00
|
|
|
QString WMTS::style(QXmlStreamReader &reader)
|
2018-02-24 01:59:03 +01:00
|
|
|
{
|
|
|
|
QString id;
|
|
|
|
|
|
|
|
while (reader.readNextStartElement()) {
|
2020-12-22 22:09:09 +01:00
|
|
|
if (reader.name() == QLatin1String("Identifier"))
|
2018-02-24 01:59:03 +01:00
|
|
|
id = reader.readElementText();
|
2018-02-26 22:35:58 +01:00
|
|
|
else
|
|
|
|
reader.skipCurrentElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2018-02-27 21:50:29 +01:00
|
|
|
void WMTS::layer(QXmlStreamReader &reader, CTX &ctx)
|
2018-02-26 22:35:58 +01:00
|
|
|
{
|
2018-02-27 21:50:29 +01:00
|
|
|
while (reader.readNextStartElement()) {
|
2020-12-22 22:09:09 +01:00
|
|
|
if (reader.name() == QLatin1String("Identifier")) {
|
2020-03-17 21:06:51 +01:00
|
|
|
if (reader.readElementText() == _setup.layer())
|
2018-10-15 00:20:20 +02:00
|
|
|
ctx.hasLayer = true;
|
|
|
|
else {
|
|
|
|
skipParentElement(reader);
|
|
|
|
return;
|
|
|
|
}
|
2020-12-22 22:09:09 +01:00
|
|
|
} else if (reader.name() == QLatin1String("TileMatrixSetLink"))
|
2018-02-27 21:50:29 +01:00
|
|
|
tileMatrixSetLink(reader, ctx);
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("WGS84BoundingBox"))
|
2020-03-17 21:06:51 +01:00
|
|
|
ctx.bbox = wgs84BoundingBox(reader);
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("ResourceURL")) {
|
2018-02-27 21:50:29 +01:00
|
|
|
const QXmlStreamAttributes &attr = reader.attributes();
|
2020-12-22 22:09:09 +01:00
|
|
|
if (attr.value("resourceType") == QLatin1String("tile")
|
|
|
|
&& _setup.rest())
|
2018-10-15 00:20:20 +02:00
|
|
|
_tileUrl = attr.value("template").toString();
|
2018-02-27 21:50:29 +01:00
|
|
|
reader.skipCurrentElement();
|
2020-12-22 22:09:09 +01:00
|
|
|
} else if (reader.name() == QLatin1String("Style")) {
|
2018-10-15 00:20:20 +02:00
|
|
|
const QXmlStreamAttributes &attr = reader.attributes();
|
2020-12-22 22:09:09 +01:00
|
|
|
bool isDefault = (attr.value("isDefault") == QLatin1String("true"));
|
2018-10-15 00:20:20 +02:00
|
|
|
QString s = style(reader);
|
|
|
|
if (isDefault)
|
|
|
|
ctx.defaultStyle = s;
|
2020-03-17 21:06:51 +01:00
|
|
|
if (s == _setup.style())
|
2018-10-15 00:20:20 +02:00
|
|
|
ctx.hasStyle = true;
|
2020-12-22 22:09:09 +01:00
|
|
|
} else if (reader.name() == QLatin1String("Format")) {
|
2020-03-01 13:26:19 +01:00
|
|
|
QString format(reader.readElementText());
|
2020-03-17 21:06:51 +01:00
|
|
|
if (bareFormat(format) == bareFormat(_setup.format()))
|
2018-10-15 00:20:20 +02:00
|
|
|
ctx.hasFormat = true;
|
|
|
|
} else
|
2018-02-27 21:50:29 +01:00
|
|
|
reader.skipCurrentElement();
|
2018-02-24 01:59:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 21:50:29 +01:00
|
|
|
void WMTS::contents(QXmlStreamReader &reader, CTX &ctx)
|
2018-02-20 23:37:19 +01:00
|
|
|
{
|
2018-02-27 21:50:29 +01:00
|
|
|
while (reader.readNextStartElement()) {
|
2020-12-22 22:09:09 +01:00
|
|
|
if (reader.name() == QLatin1String("TileMatrixSet"))
|
2018-02-27 21:50:29 +01:00
|
|
|
tileMatrixSet(reader, ctx);
|
2020-12-22 22:09:09 +01:00
|
|
|
else if (reader.name() == QLatin1String("Layer"))
|
2018-02-27 21:50:29 +01:00
|
|
|
layer(reader, ctx);
|
2018-02-20 23:37:19 +01:00
|
|
|
else
|
2018-02-27 21:50:29 +01:00
|
|
|
reader.skipCurrentElement();
|
2018-02-20 23:37:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 21:50:29 +01:00
|
|
|
void WMTS::capabilities(QXmlStreamReader &reader, CTX &ctx)
|
2018-02-20 23:37:19 +01:00
|
|
|
{
|
2018-02-27 21:50:29 +01:00
|
|
|
while (reader.readNextStartElement()) {
|
2020-12-22 22:09:09 +01:00
|
|
|
if (reader.name() == QLatin1String("Contents"))
|
2018-02-27 21:50:29 +01:00
|
|
|
contents(reader, ctx);
|
2018-02-20 23:37:19 +01:00
|
|
|
else
|
2018-02-27 21:50:29 +01:00
|
|
|
reader.skipCurrentElement();
|
2018-02-20 23:37:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-15 00:20:20 +02:00
|
|
|
void WMTS::createZooms(const CTX &ctx)
|
|
|
|
{
|
|
|
|
for (QSet<TileMatrix>::const_iterator mi = ctx.matrixes.constBegin();
|
|
|
|
mi != ctx.matrixes.constEnd(); ++mi) {
|
|
|
|
QSet<MatrixLimits>::const_iterator li = ctx.limits.find(
|
|
|
|
MatrixLimits(mi->id));
|
|
|
|
if (!ctx.limits.isEmpty() && li == ctx.limits.constEnd())
|
|
|
|
continue;
|
|
|
|
_zooms.append(Zoom(mi->id, mi->scaleDenominator, mi->topLeft, mi->tile,
|
|
|
|
mi->matrix, li == ctx.limits.constEnd() ? QRect() : li->rect));
|
|
|
|
}
|
|
|
|
|
2020-12-22 22:09:09 +01:00
|
|
|
std::sort(_zooms.begin(), _zooms.end());
|
2018-10-15 00:20:20 +02:00
|
|
|
}
|
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
bool WMTS::parseCapabilities(CTX &ctx)
|
2018-02-20 23:37:19 +01:00
|
|
|
{
|
2020-03-17 21:06:51 +01:00
|
|
|
QFile file(_path);
|
2018-02-27 21:50:29 +01:00
|
|
|
QXmlStreamReader reader;
|
2018-02-20 23:37:19 +01:00
|
|
|
|
|
|
|
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
|
|
|
_errorString = file.errorString();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-27 21:50:29 +01:00
|
|
|
reader.setDevice(&file);
|
|
|
|
if (reader.readNextStartElement()) {
|
2020-12-22 22:09:09 +01:00
|
|
|
if (reader.name() == QLatin1String("Capabilities"))
|
2018-02-27 21:50:29 +01:00
|
|
|
capabilities(reader, ctx);
|
2018-02-20 23:37:19 +01:00
|
|
|
else
|
2018-02-27 21:50:29 +01:00
|
|
|
reader.raiseError("Not a Capabilities XML file");
|
2018-02-26 22:35:58 +01:00
|
|
|
}
|
2018-02-27 21:50:29 +01:00
|
|
|
if (reader.error()) {
|
2020-03-17 21:06:51 +01:00
|
|
|
_errorString = QString("%1:%2: %3").arg(_path).arg(reader.lineNumber())
|
2018-02-27 21:50:29 +01:00
|
|
|
.arg(reader.errorString());
|
2018-02-26 22:35:58 +01:00
|
|
|
return false;
|
2018-02-20 23:37:19 +01:00
|
|
|
}
|
|
|
|
|
2018-04-03 22:35:13 +02:00
|
|
|
if (!ctx.hasLayer) {
|
2020-03-17 21:06:51 +01:00
|
|
|
_errorString = _setup.layer() + ": layer not provided";
|
2018-02-26 22:35:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-03-17 21:06:51 +01:00
|
|
|
if (!ctx.hasStyle && !_setup.style().isEmpty()) {
|
|
|
|
_errorString = _setup.style() + ": style not provided";
|
2018-02-26 22:35:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-03-17 21:06:51 +01:00
|
|
|
if (!ctx.hasStyle && _setup.style().isEmpty()
|
2019-02-15 20:32:53 +01:00
|
|
|
&& ctx.defaultStyle.isEmpty()) {
|
2018-10-15 00:20:20 +02:00
|
|
|
_errorString = "Default style not provided";
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-17 21:06:51 +01:00
|
|
|
if (!_setup.rest() && !ctx.hasFormat) {
|
|
|
|
_errorString = _setup.format() + ": format not provided";
|
2018-02-26 22:35:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
2018-04-03 22:35:13 +02:00
|
|
|
if (!ctx.hasSet) {
|
2020-03-17 21:06:51 +01:00
|
|
|
_errorString = _setup.set() + ": set not provided";
|
2018-02-26 22:35:58 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ctx.crs.isNull()) {
|
|
|
|
_errorString = "Missing CRS definition";
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-30 10:25:05 +02:00
|
|
|
_projection = CRS::projection(ctx.crs);
|
2018-05-16 18:52:48 +02:00
|
|
|
if (!_projection.isValid()) {
|
2018-02-26 22:35:58 +01:00
|
|
|
_errorString = ctx.crs + ": unknown CRS";
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-26 18:47:34 +02:00
|
|
|
createZooms(ctx);
|
|
|
|
if (_zooms.isEmpty()) {
|
2018-02-26 22:35:58 +01:00
|
|
|
_errorString = "No usable tile matrix found";
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-17 21:06:51 +01:00
|
|
|
if (_setup.rest() && _tileUrl.isNull()) {
|
2018-02-26 22:35:58 +01:00
|
|
|
_errorString = "Missing tile URL template";
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-17 21:06:51 +01:00
|
|
|
_bbox = ctx.bbox;
|
|
|
|
_cs = (_setup.coordinateSystem().axisOrder() == CoordinateSystem::Unknown)
|
|
|
|
? _projection.coordinateSystem() : _setup.coordinateSystem();
|
2018-02-20 23:37:19 +01:00
|
|
|
|
2018-02-26 22:35:58 +01:00
|
|
|
return true;
|
2018-02-20 23:37:19 +01:00
|
|
|
}
|
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
bool WMTS::downloadCapabilities(const QString &url)
|
2018-02-20 23:37:19 +01:00
|
|
|
{
|
2020-03-17 21:06:51 +01:00
|
|
|
if (!_downloader) {
|
|
|
|
_downloader = new Downloader(this);
|
2021-04-28 00:01:07 +02:00
|
|
|
connect(_downloader, &Downloader::finished, this,
|
|
|
|
&WMTS::capabilitiesReady);
|
2020-03-17 21:06:51 +01:00
|
|
|
}
|
2018-02-20 23:37:19 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
QList<Download> dl;
|
|
|
|
dl.append(Download(url, _path));
|
2018-02-20 23:37:19 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
return _downloader->get(dl, _setup.authorization());
|
|
|
|
}
|
2018-02-20 23:37:19 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
void WMTS::capabilitiesReady()
|
|
|
|
{
|
|
|
|
if (!QFileInfo(_path).exists()) {
|
2018-02-20 23:37:19 +01:00
|
|
|
_errorString = "Error downloading capabilities XML file";
|
2020-03-17 21:06:51 +01:00
|
|
|
_valid = false;
|
|
|
|
} else {
|
|
|
|
_ready = true;
|
|
|
|
_valid = init();
|
2018-02-20 23:37:19 +01:00
|
|
|
}
|
2019-03-05 22:34:50 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
emit downloadFinished();
|
2018-02-20 23:37:19 +01:00
|
|
|
}
|
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
bool WMTS::init()
|
2018-02-20 23:37:19 +01:00
|
|
|
{
|
2020-03-17 21:06:51 +01:00
|
|
|
CTX ctx;
|
|
|
|
if (!parseCapabilities(ctx))
|
|
|
|
return false;
|
2018-02-20 23:37:19 +01:00
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
QString style = _setup.style().isEmpty() ? ctx.defaultStyle : _setup.style();
|
|
|
|
if (!_setup.rest()) {
|
2018-09-16 12:05:11 +02:00
|
|
|
_tileUrl = QString("%1%2service=WMTS&Version=1.0.0&request=GetTile"
|
|
|
|
"&Format=%3&Layer=%4&Style=%5&TileMatrixSet=%6&TileMatrix=$z"
|
2020-03-17 21:06:51 +01:00
|
|
|
"&TileRow=$y&TileCol=$x").arg(_setup.url(),
|
|
|
|
_setup.url().contains('?') ? "&" : "?" , _setup.format(),
|
|
|
|
_setup.layer(), style, _setup.set());
|
|
|
|
for (int i = 0; i < _setup.dimensions().size(); i++) {
|
|
|
|
const KV<QString, QString> &dim = _setup.dimensions().at(i);
|
2018-09-30 12:16:41 +02:00
|
|
|
_tileUrl.append(QString("&%1=%2").arg(dim.key(), dim.value()));
|
2018-03-11 10:31:41 +01:00
|
|
|
}
|
|
|
|
} else {
|
2018-04-03 22:35:13 +02:00
|
|
|
_tileUrl.replace("{Style}", style, Qt::CaseInsensitive);
|
2020-03-17 21:06:51 +01:00
|
|
|
_tileUrl.replace("{TileMatrixSet}", _setup.set(), Qt::CaseInsensitive);
|
2018-03-11 19:23:40 +01:00
|
|
|
_tileUrl.replace("{TileMatrix}", "$z", Qt::CaseInsensitive);
|
|
|
|
_tileUrl.replace("{TileRow}", "$y", Qt::CaseInsensitive);
|
|
|
|
_tileUrl.replace("{TileCol}", "$x", Qt::CaseInsensitive);
|
2020-03-17 21:06:51 +01:00
|
|
|
for (int i = 0; i < _setup.dimensions().size(); i++) {
|
|
|
|
const KV<QString, QString> &dim = _setup.dimensions().at(i);
|
2018-09-30 12:16:41 +02:00
|
|
|
_tileUrl.replace(QString("{%1}").arg(dim.key()), dim.value(),
|
2018-03-11 19:23:40 +01:00
|
|
|
Qt::CaseInsensitive);
|
2018-03-11 10:31:41 +01:00
|
|
|
}
|
2018-02-25 02:31:01 +01:00
|
|
|
}
|
|
|
|
|
2020-03-17 21:06:51 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
WMTS::WMTS(const QString &file, const WMTS::Setup &setup, QObject *parent)
|
|
|
|
: QObject(parent), _setup(setup), _downloader(0), _valid(false), _ready(false)
|
|
|
|
{
|
|
|
|
QUrl url(setup.rest() ? setup.url() : QString(
|
|
|
|
"%1%2service=WMTS&Version=1.0.0&request=GetCapabilities").arg(setup.url(),
|
|
|
|
setup.url().contains('?') ? "&" : "?"));
|
|
|
|
|
|
|
|
_path = url.isLocalFile() ? url.toLocalFile() : file;
|
|
|
|
|
|
|
|
if (!url.isLocalFile() && !QFileInfo(file).exists())
|
|
|
|
_valid = downloadCapabilities(url.toString());
|
|
|
|
else {
|
|
|
|
_ready = true;
|
|
|
|
_valid = init();
|
|
|
|
}
|
2018-02-20 23:37:19 +01:00
|
|
|
}
|
2018-02-24 01:59:03 +01:00
|
|
|
|
|
|
|
#ifndef QT_NO_DEBUG
|
2018-02-25 02:31:01 +01:00
|
|
|
QDebug operator<<(QDebug dbg, const WMTS::Setup &setup)
|
|
|
|
{
|
2018-03-30 10:25:05 +02:00
|
|
|
dbg.nospace() << "Setup(" << setup.url() << ", " << setup.layer() << ", "
|
|
|
|
<< setup.set() << ", " << setup.style() << ", " << setup.format() << ", "
|
|
|
|
<< setup.rest() << ")";
|
2018-02-25 02:31:01 +01:00
|
|
|
return dbg.space();
|
|
|
|
}
|
|
|
|
|
2018-02-24 01:59:03 +01:00
|
|
|
QDebug operator<<(QDebug dbg, const WMTS::Zoom &zoom)
|
|
|
|
{
|
2018-03-30 10:25:05 +02:00
|
|
|
dbg.nospace() << "Zoom(" << zoom.id() << ", " << zoom.scaleDenominator()
|
|
|
|
<< ", " << zoom.topLeft() << ", " << zoom.tile() << ", " << zoom.matrix()
|
|
|
|
<< ", " << zoom.limits() << ")";
|
2018-02-24 01:59:03 +01:00
|
|
|
return dbg.space();
|
|
|
|
}
|
|
|
|
#endif // QT_NO_DEBUG
|