diff --git a/src/map/mapsource.cpp b/src/map/mapsource.cpp index b0c8ff95..4f0cf81d 100644 --- a/src/map/mapsource.cpp +++ b/src/map/mapsource.cpp @@ -119,8 +119,20 @@ RectC MapSource::bounds(QXmlStreamReader &reader) void MapSource::map(QXmlStreamReader &reader, Config &config) { const QXmlStreamAttributes &attr = reader.attributes(); - config.type = (attr.value("type") == "WMTS") ? WMTS - : (attr.value("type") == "WMS") ? WMS : OSM; + QStringRef type = attr.value("type"); + + if (type == "WMTS") + config.type = WMTS; + else if (type == "WMS") + config.type = WMS; + else if (type == "TMS") + config.type = TMS; + else if (type == "OSM" || type.isEmpty()) + config.type = OSM; + else { + reader.raiseError("Invalid map type"); + return; + } while (reader.readNextStartElement()) { if (reader.name() == "name") @@ -231,16 +243,23 @@ Map *MapSource::loadMap(const QString &path, QString &errorString) } } - if (config.type == WMTS) - return new WMTSMap(config.name, WMTS::Setup(config.url, config.layer, - config.set, config.style, config.format, config.rest, - config.coordinateSystem, config.dimensions, config.authorization), - config.tileRatio); - else if (config.type == WMS) - return new WMSMap(config.name, WMS::Setup(config.url, config.layer, - config.style, config.format, config.crs, config.coordinateSystem, - config.dimensions, config.authorization)); - else - return new OnlineMap(config.name, config.url, config.zooms, - config.bounds, config.tileRatio, config.authorization); + switch (config.type) { + case WMTS: + return new WMTSMap(config.name, WMTS::Setup(config.url, config.layer, + config.set, config.style, config.format, config.rest, + config.coordinateSystem, config.dimensions, config.authorization), + config.tileRatio); + case WMS: + return new WMSMap(config.name, WMS::Setup(config.url, config.layer, + config.style, config.format, config.crs, config.coordinateSystem, + config.dimensions, config.authorization)); + case TMS: + return new OnlineMap(config.name, config.url, config.zooms, + config.bounds, config.tileRatio, config.authorization, true); + case OSM: + return new OnlineMap(config.name, config.url, config.zooms, + config.bounds, config.tileRatio, config.authorization, false); + default: + return 0; + } } diff --git a/src/map/mapsource.h b/src/map/mapsource.h index f01f7cbb..7bed218b 100644 --- a/src/map/mapsource.h +++ b/src/map/mapsource.h @@ -19,7 +19,8 @@ private: enum Type { OSM, WMTS, - WMS + WMS, + TMS }; struct Config { diff --git a/src/map/onlinemap.cpp b/src/map/onlinemap.cpp index fd0b3605..795b9dfa 100644 --- a/src/map/onlinemap.cpp +++ b/src/map/onlinemap.cpp @@ -12,9 +12,10 @@ OnlineMap::OnlineMap(const QString &name, const QString &url, const Range &zooms, const RectC &bounds, qreal tileRatio, - const Authorization &authorization, QObject *parent) + const Authorization &authorization, bool invertY, QObject *parent) : Map(parent), _name(name), _zooms(zooms), _bounds(bounds), - _zoom(_zooms.max()), _deviceRatio(1.0), _tileRatio(tileRatio), _valid(false) + _zoom(_zooms.max()), _deviceRatio(1.0), _tileRatio(tileRatio), + _invertY(invertY), _valid(false) { QString dir(TILES_DIR + "/" + _name); @@ -111,7 +112,8 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags) qMin(rect.bottom() - tl.y(), b.height())); for (int i = 0; i < ceil(s.width() / tileSize()); i++) for (int j = 0; j < ceil(s.height() / tileSize()); j++) - tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom)); + tiles.append(Tile(QPoint(tile.x() + i, + _invertY ? (1<<_zoom) - (tile.y() + j) - 1 : tile.y() + j), _zoom)); if (flags & Map::Block) _tileLoader->loadTilesSync(tiles); @@ -121,7 +123,8 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags) for (int i = 0; i < tiles.count(); i++) { Tile &t = tiles[i]; QPointF tp(qMax(tl.x(), b.left()) + (t.xy().x() - tile.x()) * tileSize(), - qMax(tl.y(), b.top()) + (t.xy().y() - tile.y()) * tileSize()); + qMax(tl.y(), b.top()) + ((_invertY ? (1<<_zoom) - t.xy().y() - 1 : + t.xy().y()) - tile.y()) * tileSize()); if (!t.pixmap().isNull()) { #ifdef ENABLE_HIDPI t.pixmap().setDevicePixelRatio(imageRatio()); diff --git a/src/map/onlinemap.h b/src/map/onlinemap.h index abc60668..a6a3b67a 100644 --- a/src/map/onlinemap.h +++ b/src/map/onlinemap.h @@ -13,7 +13,7 @@ class OnlineMap : public Map public: OnlineMap(const QString &name, const QString &url, const Range &zooms, const RectC &bounds, qreal tileRatio, const Authorization &authorization, - QObject *parent = 0); + bool invertY, QObject *parent = 0); QString name() const {return _name;} @@ -49,6 +49,7 @@ private: RectC _bounds; int _zoom; qreal _deviceRatio, _tileRatio; + bool _invertY; bool _valid; QString _errorString;