mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Added TMS maps support
This commit is contained in:
parent
65b74b146d
commit
c39298000d
@ -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)
|
||||
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);
|
||||
else if (config.type == WMS)
|
||||
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));
|
||||
else
|
||||
case TMS:
|
||||
return new OnlineMap(config.name, config.url, config.zooms,
|
||||
config.bounds, config.tileRatio, config.authorization);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,8 @@ private:
|
||||
enum Type {
|
||||
OSM,
|
||||
WMTS,
|
||||
WMS
|
||||
WMS,
|
||||
TMS
|
||||
};
|
||||
|
||||
struct Config {
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user