mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-02-26 04:00:49 +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)
|
void MapSource::map(QXmlStreamReader &reader, Config &config)
|
||||||
{
|
{
|
||||||
const QXmlStreamAttributes &attr = reader.attributes();
|
const QXmlStreamAttributes &attr = reader.attributes();
|
||||||
config.type = (attr.value("type") == "WMTS") ? WMTS
|
QStringRef type = attr.value("type");
|
||||||
: (attr.value("type") == "WMS") ? WMS : OSM;
|
|
||||||
|
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()) {
|
while (reader.readNextStartElement()) {
|
||||||
if (reader.name() == "name")
|
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,
|
return new WMTSMap(config.name, WMTS::Setup(config.url, config.layer,
|
||||||
config.set, config.style, config.format, config.rest,
|
config.set, config.style, config.format, config.rest,
|
||||||
config.coordinateSystem, config.dimensions, config.authorization),
|
config.coordinateSystem, config.dimensions, config.authorization),
|
||||||
config.tileRatio);
|
config.tileRatio);
|
||||||
else if (config.type == WMS)
|
case WMS:
|
||||||
return new WMSMap(config.name, WMS::Setup(config.url, config.layer,
|
return new WMSMap(config.name, WMS::Setup(config.url, config.layer,
|
||||||
config.style, config.format, config.crs, config.coordinateSystem,
|
config.style, config.format, config.crs, config.coordinateSystem,
|
||||||
config.dimensions, config.authorization));
|
config.dimensions, config.authorization));
|
||||||
else
|
case TMS:
|
||||||
return new OnlineMap(config.name, config.url, config.zooms,
|
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 {
|
enum Type {
|
||||||
OSM,
|
OSM,
|
||||||
WMTS,
|
WMTS,
|
||||||
WMS
|
WMS,
|
||||||
|
TMS
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Config {
|
struct Config {
|
||||||
|
@ -12,9 +12,10 @@
|
|||||||
|
|
||||||
OnlineMap::OnlineMap(const QString &name, const QString &url,
|
OnlineMap::OnlineMap(const QString &name, const QString &url,
|
||||||
const Range &zooms, const RectC &bounds, qreal tileRatio,
|
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),
|
: 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);
|
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()));
|
qMin(rect.bottom() - tl.y(), b.height()));
|
||||||
for (int i = 0; i < ceil(s.width() / tileSize()); i++)
|
for (int i = 0; i < ceil(s.width() / tileSize()); i++)
|
||||||
for (int j = 0; j < ceil(s.height() / tileSize()); j++)
|
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)
|
if (flags & Map::Block)
|
||||||
_tileLoader->loadTilesSync(tiles);
|
_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++) {
|
for (int i = 0; i < tiles.count(); i++) {
|
||||||
Tile &t = tiles[i];
|
Tile &t = tiles[i];
|
||||||
QPointF tp(qMax(tl.x(), b.left()) + (t.xy().x() - tile.x()) * tileSize(),
|
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()) {
|
if (!t.pixmap().isNull()) {
|
||||||
#ifdef ENABLE_HIDPI
|
#ifdef ENABLE_HIDPI
|
||||||
t.pixmap().setDevicePixelRatio(imageRatio());
|
t.pixmap().setDevicePixelRatio(imageRatio());
|
||||||
|
@ -13,7 +13,7 @@ class OnlineMap : public Map
|
|||||||
public:
|
public:
|
||||||
OnlineMap(const QString &name, const QString &url, const Range &zooms,
|
OnlineMap(const QString &name, const QString &url, const Range &zooms,
|
||||||
const RectC &bounds, qreal tileRatio, const Authorization &authorization,
|
const RectC &bounds, qreal tileRatio, const Authorization &authorization,
|
||||||
QObject *parent = 0);
|
bool invertY, QObject *parent = 0);
|
||||||
|
|
||||||
QString name() const {return _name;}
|
QString name() const {return _name;}
|
||||||
|
|
||||||
@ -49,6 +49,7 @@ private:
|
|||||||
RectC _bounds;
|
RectC _bounds;
|
||||||
int _zoom;
|
int _zoom;
|
||||||
qreal _deviceRatio, _tileRatio;
|
qreal _deviceRatio, _tileRatio;
|
||||||
|
bool _invertY;
|
||||||
|
|
||||||
bool _valid;
|
bool _valid;
|
||||||
QString _errorString;
|
QString _errorString;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user