mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-04-18 19:29:10 +02:00
Added support for online vector maps overzoom
This commit is contained in:
parent
6f1f5fd965
commit
148fc76d5a
@ -355,7 +355,7 @@ void AQMMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
int width = ceil(s.width() / tileSize());
|
int width = ceil(s.width() / tileSize());
|
||||||
int height = ceil(s.height() / tileSize());
|
int height = ceil(s.height() / tileSize());
|
||||||
|
|
||||||
QList<RenderTile> tiles;
|
QList<DataTile> tiles;
|
||||||
|
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
for (int j = 0; j < height; j++) {
|
for (int j = 0; j < height; j++) {
|
||||||
@ -369,15 +369,15 @@ void AQMMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
} else
|
} else
|
||||||
tiles.append(RenderTile(t, tileData(t), key));
|
tiles.append(DataTile(t, tileData(t), key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
QFuture<void> future = QtConcurrent::map(tiles, &DataTile::load);
|
||||||
future.waitForFinished();
|
future.waitForFinished();
|
||||||
|
|
||||||
for (int i = 0; i < tiles.size(); i++) {
|
for (int i = 0; i < tiles.size(); i++) {
|
||||||
const RenderTile &mt = tiles.at(i);
|
const DataTile &mt = tiles.at(i);
|
||||||
QPixmap pm(mt.pixmap());
|
QPixmap pm(mt.pixmap());
|
||||||
if (pm.isNull())
|
if (pm.isNull())
|
||||||
continue;
|
continue;
|
||||||
|
@ -251,7 +251,7 @@ void GEMFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
int width = ceil(s.width() / tileSize());
|
int width = ceil(s.width() / tileSize());
|
||||||
int height = ceil(s.height() / tileSize());
|
int height = ceil(s.height() / tileSize());
|
||||||
|
|
||||||
QList<RenderTile> tiles;
|
QList<DataTile> tiles;
|
||||||
|
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
for (int j = 0; j < height; j++) {
|
for (int j = 0; j < height; j++) {
|
||||||
@ -265,15 +265,15 @@ void GEMFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
} else
|
} else
|
||||||
tiles.append(RenderTile(t, tileData(t), key));
|
tiles.append(DataTile(t, tileData(t), key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
QFuture<void> future = QtConcurrent::map(tiles, &DataTile::load);
|
||||||
future.waitForFinished();
|
future.waitForFinished();
|
||||||
|
|
||||||
for (int i = 0; i < tiles.size(); i++) {
|
for (int i = 0; i < tiles.size(); i++) {
|
||||||
const RenderTile &mt = tiles.at(i);
|
const DataTile &mt = tiles.at(i);
|
||||||
QPixmap pm(mt.pixmap());
|
QPixmap pm(mt.pixmap());
|
||||||
if (pm.isNull())
|
if (pm.isNull())
|
||||||
continue;
|
continue;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QPixmapCache>
|
||||||
|
#include <QtConcurrent>
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
#include "common/programpaths.h"
|
#include "common/programpaths.h"
|
||||||
#include "common/downloader.h"
|
#include "common/downloader.h"
|
||||||
@ -7,12 +9,19 @@
|
|||||||
#include "onlinemap.h"
|
#include "onlinemap.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_OVERZOOM 3
|
||||||
|
|
||||||
|
static QString cacheName(const QString &file, unsigned overzoom)
|
||||||
|
{
|
||||||
|
return overzoom ? file + ":" + QString::number(overzoom) : file;
|
||||||
|
}
|
||||||
|
|
||||||
OnlineMap::OnlineMap(const QString &fileName, const QString &name,
|
OnlineMap::OnlineMap(const QString &fileName, const QString &name,
|
||||||
const QString &url, const Range &zooms, const RectC &bounds, qreal tileRatio,
|
const QString &url, const Range &zooms, const RectC &bounds, qreal tileRatio,
|
||||||
const QList<HTTPHeader> &headers, int tileSize, bool scalable, bool invertY,
|
const QList<HTTPHeader> &headers, int tileSize, bool scalable, bool invertY,
|
||||||
bool quadTiles, QObject *parent)
|
bool quadTiles, QObject *parent)
|
||||||
: Map(fileName, parent), _name(name), _zooms(zooms), _bounds(bounds),
|
: Map(fileName, parent), _name(name), _zooms(zooms), _bounds(bounds),
|
||||||
_zoom(_zooms.max()), _tileSize(tileSize), _mapRatio(1.0),
|
_zoom(_zooms.max()), _tileSize(tileSize), _base(0), _mapRatio(1.0),
|
||||||
_tileRatio(tileRatio), _scalable(scalable), _invertY(invertY)
|
_tileRatio(tileRatio), _scalable(scalable), _invertY(invertY)
|
||||||
{
|
{
|
||||||
_tileLoader = new TileLoader(QDir(ProgramPaths::tilesDir()).filePath(_name),
|
_tileLoader = new TileLoader(QDir(ProgramPaths::tilesDir()).filePath(_name),
|
||||||
@ -20,6 +29,11 @@ OnlineMap::OnlineMap(const QString &fileName, const QString &name,
|
|||||||
_tileLoader->setUrl(url, quadTiles ? TileLoader::QuadTiles : TileLoader::XYZ);
|
_tileLoader->setUrl(url, quadTiles ? TileLoader::QuadTiles : TileLoader::XYZ);
|
||||||
_tileLoader->setHeaders(headers);
|
_tileLoader->setHeaders(headers);
|
||||||
connect(_tileLoader, &TileLoader::finished, this, &OnlineMap::tilesLoaded);
|
connect(_tileLoader, &TileLoader::finished, this, &OnlineMap::tilesLoaded);
|
||||||
|
|
||||||
|
if (_scalable) {
|
||||||
|
_base = _zooms.max();
|
||||||
|
_zooms.setMax(qMin(_zooms.max() + MAX_OVERZOOM, OSM::ZOOMS.max()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF OnlineMap::bounds()
|
QRectF OnlineMap::bounds()
|
||||||
@ -77,7 +91,7 @@ void OnlineMap::load(const Projection &in, const Projection &out,
|
|||||||
_mapRatio = hidpi ? deviceRatio : 1.0;
|
_mapRatio = hidpi ? deviceRatio : 1.0;
|
||||||
|
|
||||||
if (_scalable) {
|
if (_scalable) {
|
||||||
_tileLoader->setScaledSize(_tileSize * deviceRatio);
|
_scaledSize = _tileSize * deviceRatio;
|
||||||
_tileRatio = deviceRatio;
|
_tileRatio = deviceRatio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,41 +111,77 @@ qreal OnlineMap::tileSize() const
|
|||||||
return (_tileSize / coordinatesRatio());
|
return (_tileSize / coordinatesRatio());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPoint OnlineMap::tileCoordinates(int x, int y, int zoom)
|
||||||
|
{
|
||||||
|
return QPoint(x, _invertY ? (1<<zoom) - y - 1 : y);
|
||||||
|
}
|
||||||
|
|
||||||
void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||||
{
|
{
|
||||||
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
int base = _scalable ? qMin(_base, _zoom) : _zoom;
|
||||||
|
unsigned overzoom = _zoom - base;
|
||||||
|
unsigned f = 1U<<overzoom;
|
||||||
|
|
||||||
|
qreal scale = OSM::zoom2scale(base, _tileSize * f);
|
||||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||||
-rect.topLeft().y() * scale) * coordinatesRatio(), _zoom);
|
-rect.topLeft().y() * scale) * coordinatesRatio(), base);
|
||||||
Coordinates ctl(OSM::tile2ll(tile, _zoom));
|
Coordinates ctl(OSM::tile2ll(tile, base));
|
||||||
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
||||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
||||||
int width = ceil(s.width() / tileSize());
|
int width = ceil(s.width() / (tileSize() * f));
|
||||||
int height = ceil(s.height() / tileSize());
|
int height = ceil(s.height() / (tileSize() * f));
|
||||||
|
|
||||||
QVector<FetchTile> tiles;
|
QVector<TileLoader::Tile> fetchTiles;
|
||||||
tiles.reserve(width * height);
|
fetchTiles.reserve(width * height);
|
||||||
for (int i = 0; i < width; i++)
|
for (int i = 0; i < width; i++) {
|
||||||
for (int j = 0; j < height; j++)
|
for (int j = 0; j < height; j++) {
|
||||||
tiles.append(FetchTile(QPoint(tile.x() + i, _invertY ? (1<<_zoom)
|
QPoint tc(tileCoordinates(tile.x() + i, tile.y() + j, base));
|
||||||
- (tile.y() + j) - 1 : tile.y() + j), _zoom));
|
fetchTiles.append(TileLoader::Tile(tc, base));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (flags & Map::Block)
|
if (flags & Map::Block)
|
||||||
_tileLoader->loadTilesSync(tiles);
|
_tileLoader->loadTilesSync(fetchTiles);
|
||||||
else
|
else
|
||||||
_tileLoader->loadTilesAsync(tiles);
|
_tileLoader->loadTilesAsync(fetchTiles);
|
||||||
|
|
||||||
for (int i = 0; i < tiles.count(); i++) {
|
QList<OnlineTile> renderTiles;
|
||||||
FetchTile &t = tiles[i];
|
for (int i = 0; i < fetchTiles.count(); i++) {
|
||||||
QPointF tp(tl.x() + (t.xy().x() - tile.x()) * tileSize(),
|
const TileLoader::Tile &t = fetchTiles.at(i);
|
||||||
tl.y() + ((_invertY
|
if (t.file().isNull())
|
||||||
? (1<<_zoom) - t.xy().y() - 1
|
continue;
|
||||||
: t.xy().y()) - tile.y()) * tileSize());
|
|
||||||
|
|
||||||
if (!t.pixmap().isNull()) {
|
QPixmap pm;
|
||||||
t.pixmap().setDevicePixelRatio(imageRatio());
|
if (QPixmapCache::find(cacheName(t.file(), overzoom), &pm)) {
|
||||||
painter->drawPixmap(tp, t.pixmap());
|
QPointF tp(tl.x() + (t.xy().x() - tile.x()) * tileSize() * f,
|
||||||
|
tl.y() + (t.xy().y() - tile.y()) * tileSize() * f);
|
||||||
|
drawTile(painter, pm, tp);
|
||||||
|
} else
|
||||||
|
renderTiles.append(OnlineTile(t.xy(), t.file(), _zoom, overzoom,
|
||||||
|
_scaledSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
QFuture<void> future = QtConcurrent::map(renderTiles, &OnlineTile::load);
|
||||||
|
future.waitForFinished();
|
||||||
|
|
||||||
|
for (int i = 0; i < renderTiles.size(); i++) {
|
||||||
|
const OnlineTile &mt = renderTiles.at(i);
|
||||||
|
QPixmap pm(mt.pixmap());
|
||||||
|
if (pm.isNull())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QPixmapCache::insert(cacheName(mt.file(), overzoom), pm);
|
||||||
|
|
||||||
|
QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize() * f,
|
||||||
|
tl.y() + (mt.xy().y() - tile.y()) * tileSize() * f);
|
||||||
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnlineMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp)
|
||||||
|
{
|
||||||
|
pixmap.setDevicePixelRatio(imageRatio());
|
||||||
|
painter->drawPixmap(tp, pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF OnlineMap::ll2xy(const Coordinates &c)
|
QPointF OnlineMap::ll2xy(const Coordinates &c)
|
||||||
@ -147,3 +197,9 @@ Coordinates OnlineMap::xy2ll(const QPointF &p)
|
|||||||
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale)
|
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale)
|
||||||
* coordinatesRatio());
|
* coordinatesRatio());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnlineMap::clearCache()
|
||||||
|
{
|
||||||
|
_tileLoader->clearCache();
|
||||||
|
QPixmapCache::clear();
|
||||||
|
}
|
||||||
|
@ -1,11 +1,44 @@
|
|||||||
#ifndef ONLINEMAP_H
|
#ifndef ONLINEMAP_H
|
||||||
#define ONLINEMAP_H
|
#define ONLINEMAP_H
|
||||||
|
|
||||||
|
#include <QImageReader>
|
||||||
|
#include <QPixmap>
|
||||||
#include "common/range.h"
|
#include "common/range.h"
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "tileloader.h"
|
#include "tileloader.h"
|
||||||
|
|
||||||
|
class OnlineTile
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OnlineTile(const QPoint &xy, const QString &file, int zoom, int overzoom,
|
||||||
|
int scaledSize) : _xy(xy), _file(file), _zoom(zoom), _overzoom(overzoom),
|
||||||
|
_scaledSize(scaledSize) {}
|
||||||
|
|
||||||
|
void load()
|
||||||
|
{
|
||||||
|
QByteArray format(_overzoom
|
||||||
|
? QByteArray::number(_zoom) + ';' + QByteArray::number(_overzoom)
|
||||||
|
: QByteArray::number(_zoom));
|
||||||
|
QImageReader reader(_file, format);
|
||||||
|
if (_scaledSize)
|
||||||
|
reader.setScaledSize(QSize(_scaledSize, _scaledSize));
|
||||||
|
_pixmap = QPixmap::fromImage(reader.read());
|
||||||
|
}
|
||||||
|
|
||||||
|
const QPoint &xy() const {return _xy;}
|
||||||
|
const QString &file() const {return _file;}
|
||||||
|
const QPixmap &pixmap() const {return _pixmap;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPoint _xy;
|
||||||
|
QString _file;
|
||||||
|
int _zoom;
|
||||||
|
int _overzoom;
|
||||||
|
int _scaledSize;
|
||||||
|
QPixmap _pixmap;
|
||||||
|
};
|
||||||
|
|
||||||
class OnlineMap : public Map
|
class OnlineMap : public Map
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -35,13 +68,15 @@ public:
|
|||||||
|
|
||||||
void load(const Projection &in, const Projection &out, qreal deviceRatio,
|
void load(const Projection &in, const Projection &out, qreal deviceRatio,
|
||||||
bool hidpi);
|
bool hidpi);
|
||||||
void clearCache() {_tileLoader->clearCache();}
|
void clearCache();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int limitZoom(int zoom) const;
|
int limitZoom(int zoom) const;
|
||||||
qreal tileSize() const;
|
qreal tileSize() const;
|
||||||
qreal coordinatesRatio() const;
|
qreal coordinatesRatio() const;
|
||||||
qreal imageRatio() const;
|
qreal imageRatio() const;
|
||||||
|
QPoint tileCoordinates(int x, int y, int zoom);
|
||||||
|
void drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp);
|
||||||
|
|
||||||
TileLoader *_tileLoader;
|
TileLoader *_tileLoader;
|
||||||
QString _name;
|
QString _name;
|
||||||
@ -49,8 +84,10 @@ private:
|
|||||||
RectC _bounds;
|
RectC _bounds;
|
||||||
int _zoom;
|
int _zoom;
|
||||||
int _tileSize;
|
int _tileSize;
|
||||||
|
int _base;
|
||||||
qreal _mapRatio, _tileRatio;
|
qreal _mapRatio, _tileRatio;
|
||||||
bool _scalable;
|
bool _scalable;
|
||||||
|
int _scaledSize;
|
||||||
bool _invertY;
|
bool _invertY;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ void OsmdroidMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
int width = ceil(s.width() / tileSize());
|
int width = ceil(s.width() / tileSize());
|
||||||
int height = ceil(s.height() / tileSize());
|
int height = ceil(s.height() / tileSize());
|
||||||
|
|
||||||
QList<RenderTile> tiles;
|
QList<DataTile> tiles;
|
||||||
|
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
for (int j = 0; j < height; j++) {
|
for (int j = 0; j < height; j++) {
|
||||||
@ -260,15 +260,15 @@ void OsmdroidMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
} else
|
} else
|
||||||
tiles.append(RenderTile(t, tileData(_zoom, t), key));
|
tiles.append(DataTile(t, tileData(_zoom, t), key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
QFuture<void> future = QtConcurrent::map(tiles, &DataTile::load);
|
||||||
future.waitForFinished();
|
future.waitForFinished();
|
||||||
|
|
||||||
for (int i = 0; i < tiles.size(); i++) {
|
for (int i = 0; i < tiles.size(); i++) {
|
||||||
const RenderTile &mt = tiles.at(i);
|
const DataTile &mt = tiles.at(i);
|
||||||
QPixmap pm(mt.pixmap());
|
QPixmap pm(mt.pixmap());
|
||||||
if (pm.isNull())
|
if (pm.isNull())
|
||||||
continue;
|
continue;
|
||||||
|
@ -193,7 +193,7 @@ void SqliteMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
int width = ceil(s.width() / tileSize());
|
int width = ceil(s.width() / tileSize());
|
||||||
int height = ceil(s.height() / tileSize());
|
int height = ceil(s.height() / tileSize());
|
||||||
|
|
||||||
QList<RenderTile> tiles;
|
QList<DataTile> tiles;
|
||||||
|
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
for (int j = 0; j < height; j++) {
|
for (int j = 0; j < height; j++) {
|
||||||
@ -207,15 +207,15 @@ void SqliteMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
} else
|
} else
|
||||||
tiles.append(RenderTile(t, tileData(_zoom, t), key));
|
tiles.append(DataTile(t, tileData(_zoom, t), key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
QFuture<void> future = QtConcurrent::map(tiles, &DataTile::load);
|
||||||
future.waitForFinished();
|
future.waitForFinished();
|
||||||
|
|
||||||
for (int i = 0; i < tiles.size(); i++) {
|
for (int i = 0; i < tiles.size(); i++) {
|
||||||
const RenderTile &mt = tiles.at(i);
|
const DataTile &mt = tiles.at(i);
|
||||||
QPixmap pm(mt.pixmap());
|
QPixmap pm(mt.pixmap());
|
||||||
if (pm.isNull())
|
if (pm.isNull())
|
||||||
continue;
|
continue;
|
||||||
|
@ -4,32 +4,29 @@
|
|||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QDebug>
|
|
||||||
#include "rectd.h"
|
|
||||||
|
|
||||||
class FetchTile
|
class FileTile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FetchTile() {}
|
FileTile(const QPoint &xy, const QString &file)
|
||||||
FetchTile(const QPoint &xy, const QVariant &zoom, const RectD &bbox = RectD())
|
: _xy(xy), _file(file) {}
|
||||||
: _xy(xy), _zoom(zoom), _bbox(bbox) {}
|
|
||||||
|
|
||||||
const QVariant &zoom() const {return _zoom;}
|
|
||||||
const QPoint &xy() const {return _xy;}
|
const QPoint &xy() const {return _xy;}
|
||||||
const RectD &bbox() const {return _bbox;}
|
const QString &file() const {return _file;}
|
||||||
QPixmap &pixmap() {return _pixmap;}
|
const QPixmap &pixmap() const {return _pixmap;}
|
||||||
|
|
||||||
|
void load() {_pixmap.load(_file);}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPoint _xy;
|
QPoint _xy;
|
||||||
QVariant _zoom;
|
QString _file;
|
||||||
RectD _bbox;
|
|
||||||
QPixmap _pixmap;
|
QPixmap _pixmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RenderTile
|
class DataTile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RenderTile(const QPoint &xy, const QByteArray &data, const QString &key)
|
DataTile(const QPoint &xy, const QByteArray &data, const QString &key)
|
||||||
: _xy(xy), _data(data), _key(key) {}
|
: _xy(xy), _data(data), _key(key) {}
|
||||||
|
|
||||||
const QPoint &xy() const {return _xy;}
|
const QPoint &xy() const {return _xy;}
|
||||||
@ -45,13 +42,4 @@ private:
|
|||||||
QPixmap _pixmap;
|
QPixmap _pixmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG
|
|
||||||
inline QDebug operator<<(QDebug dbg, const FetchTile &tile)
|
|
||||||
{
|
|
||||||
dbg.nospace() << "Tile(" << tile.zoom() << ", " << tile.xy() << ", "
|
|
||||||
<< tile.bbox() << ")";
|
|
||||||
return dbg.space();
|
|
||||||
}
|
|
||||||
#endif // QT_NO_DEBUG
|
|
||||||
|
|
||||||
#endif // TILE_H
|
#endif // TILE_H
|
||||||
|
@ -1,42 +1,12 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QPixmapCache>
|
|
||||||
#include <QImageReader>
|
|
||||||
#include <QtConcurrent>
|
|
||||||
#include "tileloader.h"
|
#include "tileloader.h"
|
||||||
|
|
||||||
#define SUBSTITUTE_CHAR '$'
|
#define SUBSTITUTE_CHAR '$'
|
||||||
#define IS_INT(zoom) \
|
#define IS_INT(zoom) \
|
||||||
((QMetaType::Type)((zoom).type()) == QMetaType::Int)
|
((QMetaType::Type)((zoom).type()) == QMetaType::Int)
|
||||||
|
|
||||||
class TileImage
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TileImage() : _tile(0), _scaledSize(0) {}
|
|
||||||
TileImage(const QString &file, FetchTile *tile, int scaledSize)
|
|
||||||
: _file(file), _tile(tile), _scaledSize(scaledSize) {}
|
|
||||||
|
|
||||||
void load()
|
|
||||||
{
|
|
||||||
QImage img;
|
|
||||||
QByteArray z(IS_INT(_tile->zoom())
|
|
||||||
? QByteArray::number(_tile->zoom().toInt()) : QByteArray());
|
|
||||||
QImageReader reader(_file, z);
|
|
||||||
if (_scaledSize)
|
|
||||||
reader.setScaledSize(QSize(_scaledSize, _scaledSize));
|
|
||||||
reader.read(&img);
|
|
||||||
_tile->pixmap().convertFromImage(img);
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString &file() const {return _file;}
|
|
||||||
FetchTile *tile() {return _tile;}
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString _file;
|
|
||||||
FetchTile *_tile;
|
|
||||||
int _scaledSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
static QString fsSafeStr(const QString &str)
|
static QString fsSafeStr(const QString &str)
|
||||||
{
|
{
|
||||||
@ -77,7 +47,7 @@ static QString quadKey(const QPoint &xy, int zoom)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TileLoader::TileLoader(const QString &dir, QObject *parent)
|
TileLoader::TileLoader(const QString &dir, QObject *parent)
|
||||||
: QObject(parent), _urlType(XYZ), _dir(dir), _scaledSize(0)
|
: QObject(parent), _urlType(XYZ), _dir(dir)
|
||||||
{
|
{
|
||||||
if (!QDir().mkpath(_dir))
|
if (!QDir().mkpath(_dir))
|
||||||
qWarning("%s: %s", qPrintable(_dir), "Error creating tiles directory");
|
qWarning("%s: %s", qPrintable(_dir), "Error creating tiles directory");
|
||||||
@ -87,26 +57,20 @@ TileLoader::TileLoader(const QString &dir, QObject *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TileLoader::loadTilesAsync(QVector<FetchTile> &list)
|
void TileLoader::loadTilesAsync(QVector<Tile> &list)
|
||||||
{
|
{
|
||||||
QList<Download> dl;
|
QList<Download> dl;
|
||||||
QList<TileImage> imgs;
|
|
||||||
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
FetchTile &t = list[i];
|
Tile &t = list[i];
|
||||||
QString file(tileFile(t));
|
QString file(tileFile(t));
|
||||||
|
|
||||||
if (QPixmapCache::find(file, &t.pixmap()))
|
if (QFileInfo::exists(file))
|
||||||
continue;
|
t.setFile(file);
|
||||||
|
|
||||||
QFileInfo fi(file);
|
|
||||||
|
|
||||||
if (fi.exists())
|
|
||||||
imgs.append(TileImage(file, &t, _scaledSize));
|
|
||||||
else {
|
else {
|
||||||
QUrl url(tileUrl(t));
|
QUrl url(tileUrl(t));
|
||||||
if (url.isLocalFile())
|
if (url.isLocalFile())
|
||||||
imgs.append(TileImage(url.toLocalFile(), &t, _scaledSize));
|
t.setFile(url.toLocalFile());
|
||||||
else
|
else
|
||||||
dl.append(Download(url, file));
|
dl.append(Download(url, file));
|
||||||
}
|
}
|
||||||
@ -114,37 +78,23 @@ void TileLoader::loadTilesAsync(QVector<FetchTile> &list)
|
|||||||
|
|
||||||
if (!dl.empty())
|
if (!dl.empty())
|
||||||
_downloader->get(dl, _headers);
|
_downloader->get(dl, _headers);
|
||||||
|
|
||||||
QFuture<void> future = QtConcurrent::map(imgs, &TileImage::load);
|
|
||||||
future.waitForFinished();
|
|
||||||
|
|
||||||
for (int i = 0; i < imgs.size(); i++) {
|
|
||||||
TileImage &ti = imgs[i];
|
|
||||||
QPixmapCache::insert(ti.file(), ti.tile()->pixmap());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileLoader::loadTilesSync(QVector<FetchTile> &list)
|
void TileLoader::loadTilesSync(QVector<Tile> &list)
|
||||||
{
|
{
|
||||||
QList<Download> dl;
|
QList<Download> dl;
|
||||||
QList<FetchTile *> tl;
|
QList<Tile *> tl;
|
||||||
QList<TileImage> imgs;
|
|
||||||
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
FetchTile &t = list[i];
|
Tile &t = list[i];
|
||||||
QString file(tileFile(t));
|
QString file(tileFile(t));
|
||||||
|
|
||||||
if (QPixmapCache::find(file, &t.pixmap()))
|
if (QFileInfo::exists(file))
|
||||||
continue;
|
t.setFile(file);
|
||||||
|
|
||||||
QFileInfo fi(file);
|
|
||||||
|
|
||||||
if (fi.exists())
|
|
||||||
imgs.append(TileImage(file, &t, _scaledSize));
|
|
||||||
else {
|
else {
|
||||||
QUrl url(tileUrl(t));
|
QUrl url(tileUrl(t));
|
||||||
if (url.isLocalFile())
|
if (url.isLocalFile())
|
||||||
imgs.append(TileImage(url.toLocalFile(), &t, _scaledSize));
|
t.setFile(url.toLocalFile());
|
||||||
else {
|
else {
|
||||||
dl.append(Download(url, file));
|
dl.append(Download(url, file));
|
||||||
tl.append(&t);
|
tl.append(&t);
|
||||||
@ -159,20 +109,12 @@ void TileLoader::loadTilesSync(QVector<FetchTile> &list)
|
|||||||
wait.exec();
|
wait.exec();
|
||||||
|
|
||||||
for (int i = 0; i < tl.size(); i++) {
|
for (int i = 0; i < tl.size(); i++) {
|
||||||
FetchTile *t = tl[i];
|
Tile *t = tl[i];
|
||||||
QString file = tileFile(*t);
|
QString file = tileFile(*t);
|
||||||
if (QFileInfo(file).exists())
|
if (QFileInfo(file).exists())
|
||||||
imgs.append(TileImage(file, t, _scaledSize));
|
t->setFile(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<void> future = QtConcurrent::map(imgs, &TileImage::load);
|
|
||||||
future.waitForFinished();
|
|
||||||
|
|
||||||
for (int i = 0; i < imgs.size(); i++) {
|
|
||||||
TileImage &ti = imgs[i];
|
|
||||||
QPixmapCache::insert(ti.file(), ti.tile()->pixmap());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileLoader::clearCache()
|
void TileLoader::clearCache()
|
||||||
@ -184,20 +126,9 @@ void TileLoader::clearCache()
|
|||||||
dir.remove(list.at(i));
|
dir.remove(list.at(i));
|
||||||
|
|
||||||
_downloader->clearErrors();
|
_downloader->clearErrors();
|
||||||
|
|
||||||
QPixmapCache::clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileLoader::setScaledSize(int size)
|
QUrl TileLoader::tileUrl(const Tile &tile) const
|
||||||
{
|
|
||||||
if (_scaledSize == size)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_scaledSize = size;
|
|
||||||
QPixmapCache::clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
QUrl TileLoader::tileUrl(const FetchTile &tile) const
|
|
||||||
{
|
{
|
||||||
QString url(_url);
|
QString url(_url);
|
||||||
|
|
||||||
@ -221,7 +152,7 @@ QUrl TileLoader::tileUrl(const FetchTile &tile) const
|
|||||||
return QUrl(url);
|
return QUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TileLoader::tileFile(const FetchTile &tile) const
|
QString TileLoader::tileFile(const Tile &tile) const
|
||||||
{
|
{
|
||||||
QString zoom(IS_INT(tile.zoom())
|
QString zoom(IS_INT(tile.zoom())
|
||||||
? tile.zoom().toString() : fsSafeStr(tile.zoom().toString()));
|
? tile.zoom().toString() : fsSafeStr(tile.zoom().toString()));
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "common/downloader.h"
|
#include "common/downloader.h"
|
||||||
#include "tile.h"
|
#include "rectd.h"
|
||||||
|
|
||||||
class TileLoader : public QObject
|
class TileLoader : public QObject
|
||||||
{
|
{
|
||||||
@ -17,29 +17,55 @@ public:
|
|||||||
BoundingBox
|
BoundingBox
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Tile
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Tile() {}
|
||||||
|
Tile(const QPoint &xy, int zoom)
|
||||||
|
: _xy(xy), _zoom(zoom) {}
|
||||||
|
Tile(const QPoint &xy, const QString &zoom)
|
||||||
|
: _xy(xy), _zoom(zoom) {}
|
||||||
|
Tile(const QPoint &xy, int zoom, const RectD &bbox)
|
||||||
|
: _xy(xy), _zoom(zoom), _bbox(bbox) {}
|
||||||
|
|
||||||
|
const QVariant &zoom() const {return _zoom;}
|
||||||
|
const QPoint &xy() const {return _xy;}
|
||||||
|
const RectD &bbox() const {return _bbox;}
|
||||||
|
const QString &file() const {return _file;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class TileLoader;
|
||||||
|
|
||||||
|
void setFile(const QString &file) {_file = file;}
|
||||||
|
|
||||||
|
QPoint _xy;
|
||||||
|
QVariant _zoom;
|
||||||
|
RectD _bbox;
|
||||||
|
QString _file;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
TileLoader(const QString &dir, QObject *parent = 0);
|
TileLoader(const QString &dir, QObject *parent = 0);
|
||||||
|
|
||||||
void setUrl(const QString &url, UrlType type) {_url = url; _urlType = type;}
|
void setUrl(const QString &url, UrlType type) {_url = url; _urlType = type;}
|
||||||
void setHeaders(const QList<HTTPHeader> &headers) {_headers = headers;}
|
void setHeaders(const QList<HTTPHeader> &headers) {_headers = headers;}
|
||||||
void setScaledSize(int size);
|
|
||||||
|
|
||||||
void loadTilesAsync(QVector<FetchTile> &list);
|
void loadTilesAsync(QVector<Tile> &list);
|
||||||
void loadTilesSync(QVector<FetchTile> &list);
|
void loadTilesSync(QVector<Tile> &list);
|
||||||
void clearCache();
|
void clearCache();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void finished();
|
void finished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUrl tileUrl(const FetchTile &tile) const;
|
QUrl tileUrl(const Tile &tile) const;
|
||||||
QString tileFile(const FetchTile &tile) const;
|
QString tileFile(const Tile &tile) const;
|
||||||
|
|
||||||
Downloader *_downloader;
|
Downloader *_downloader;
|
||||||
QString _url;
|
QString _url;
|
||||||
UrlType _urlType;
|
UrlType _urlType;
|
||||||
QString _dir;
|
QString _dir;
|
||||||
QList<HTTPHeader> _headers;
|
QList<HTTPHeader> _headers;
|
||||||
int _scaledSize;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TILELOADER_H
|
#endif // TILELOADER_H
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QPixmapCache>
|
||||||
|
#include <QtConcurrent>
|
||||||
#include "common/wgs84.h"
|
#include "common/wgs84.h"
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
#include "common/programpaths.h"
|
#include "common/programpaths.h"
|
||||||
|
#include "tile.h"
|
||||||
#include "tileloader.h"
|
#include "tileloader.h"
|
||||||
#include "wmsmap.h"
|
#include "wmsmap.h"
|
||||||
|
|
||||||
@ -111,6 +114,7 @@ void WMSMap::load(const Projection &in, const Projection &out,
|
|||||||
void WMSMap::clearCache()
|
void WMSMap::clearCache()
|
||||||
{
|
{
|
||||||
_tileLoader->clearCache();
|
_tileLoader->clearCache();
|
||||||
|
QPixmapCache::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF WMSMap::bounds()
|
QRectF WMSMap::bounds()
|
||||||
@ -183,8 +187,8 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
QPoint br = QPoint(qCeil(rect.right() / tileSize()),
|
QPoint br = QPoint(qCeil(rect.right() / tileSize()),
|
||||||
qCeil(rect.bottom() / tileSize()));
|
qCeil(rect.bottom() / tileSize()));
|
||||||
|
|
||||||
QVector<FetchTile> tiles;
|
QVector<TileLoader::Tile> fetchTiles;
|
||||||
tiles.reserve((br.x() - tl.x()) * (br.y() - tl.y()));
|
fetchTiles.reserve((br.x() - tl.x()) * (br.y() - tl.y()));
|
||||||
for (int i = tl.x(); i < br.x(); i++) {
|
for (int i = tl.x(); i < br.x(); i++) {
|
||||||
for (int j = tl.y(); j < br.y(); j++) {
|
for (int j = tl.y(); j < br.y(); j++) {
|
||||||
PointD ttl(_transform.img2proj(QPointF(i * _tileSize,
|
PointD ttl(_transform.img2proj(QPointF(i * _tileSize,
|
||||||
@ -195,21 +199,47 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
? RectD(PointD(tbr.y(), tbr.x()), PointD(ttl.y(), ttl.x()))
|
? RectD(PointD(tbr.y(), tbr.x()), PointD(ttl.y(), ttl.x()))
|
||||||
: RectD(ttl, tbr);
|
: RectD(ttl, tbr);
|
||||||
|
|
||||||
tiles.append(FetchTile(QPoint(i, j), _zoom, bbox));
|
fetchTiles.append(TileLoader::Tile(QPoint(i, j), _zoom, bbox));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & Map::Block)
|
if (flags & Map::Block)
|
||||||
_tileLoader->loadTilesSync(tiles);
|
_tileLoader->loadTilesSync(fetchTiles);
|
||||||
else
|
else
|
||||||
_tileLoader->loadTilesAsync(tiles);
|
_tileLoader->loadTilesAsync(fetchTiles);
|
||||||
|
|
||||||
for (int i = 0; i < tiles.count(); i++) {
|
QList<FileTile> renderTiles;
|
||||||
FetchTile &t = tiles[i];
|
for (int i = 0; i < fetchTiles.count(); i++) {
|
||||||
|
const TileLoader::Tile &t = fetchTiles.at(i);
|
||||||
|
if (t.file().isNull())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QPixmap pm;
|
||||||
|
if (QPixmapCache::find(t.file(), &pm)) {
|
||||||
QPointF tp(t.xy().x() * tileSize(), t.xy().y() * tileSize());
|
QPointF tp(t.xy().x() * tileSize(), t.xy().y() * tileSize());
|
||||||
if (!t.pixmap().isNull()) {
|
drawTile(painter, pm, tp);
|
||||||
t.pixmap().setDevicePixelRatio(_mapRatio);
|
} else
|
||||||
painter->drawPixmap(tp, t.pixmap());
|
renderTiles.append(FileTile(t.xy(), t.file()));
|
||||||
|
}
|
||||||
|
|
||||||
|
QFuture<void> future = QtConcurrent::map(renderTiles, &FileTile::load);
|
||||||
|
future.waitForFinished();
|
||||||
|
|
||||||
|
for (int i = 0; i < renderTiles.size(); i++) {
|
||||||
|
const FileTile &mt = renderTiles.at(i);
|
||||||
|
QPixmap pm(mt.pixmap());
|
||||||
|
if (pm.isNull())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QPixmapCache::insert(mt.file(), pm);
|
||||||
|
|
||||||
|
QPointF tp(mt.xy().x() * tileSize(), mt.xy().y() * tileSize());
|
||||||
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WMSMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp)
|
||||||
|
{
|
||||||
|
pixmap.setDevicePixelRatio(_mapRatio);
|
||||||
|
painter->drawPixmap(tp, pixmap);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ private:
|
|||||||
void updateTransform();
|
void updateTransform();
|
||||||
qreal tileSize() const;
|
qreal tileSize() const;
|
||||||
void init();
|
void init();
|
||||||
|
void drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp);
|
||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
WMS *_wms;
|
WMS *_wms;
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QPixmapCache>
|
||||||
|
#include <QtConcurrent>
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
#include "common/wgs84.h"
|
#include "common/wgs84.h"
|
||||||
#include "common/programpaths.h"
|
#include "common/programpaths.h"
|
||||||
#include "transform.h"
|
#include "transform.h"
|
||||||
#include "tileloader.h"
|
#include "tileloader.h"
|
||||||
|
#include "tile.h"
|
||||||
#include "wmts.h"
|
#include "wmts.h"
|
||||||
#include "wmtsmap.h"
|
#include "wmtsmap.h"
|
||||||
|
|
||||||
@ -56,6 +59,7 @@ void WMTSMap::load(const Projection &in, const Projection &out,
|
|||||||
void WMTSMap::clearCache()
|
void WMTSMap::clearCache()
|
||||||
{
|
{
|
||||||
_tileLoader->clearCache();
|
_tileLoader->clearCache();
|
||||||
|
QPixmapCache::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
double WMTSMap::sd2res(double scaleDenominator) const
|
double WMTSMap::sd2res(double scaleDenominator) const
|
||||||
@ -189,25 +193,51 @@ void WMTSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
QPoint br = QPoint(qCeil(rect.right() / ts.width()),
|
QPoint br = QPoint(qCeil(rect.right() / ts.width()),
|
||||||
qCeil(rect.bottom() / ts.height()));
|
qCeil(rect.bottom() / ts.height()));
|
||||||
|
|
||||||
QVector<FetchTile> tiles;
|
QVector<TileLoader::Tile> fetchTiles;
|
||||||
tiles.reserve((br.x() - tl.x()) * (br.y() - tl.y()));
|
fetchTiles.reserve((br.x() - tl.x()) * (br.y() - tl.y()));
|
||||||
for (int i = tl.x(); i < br.x(); i++)
|
for (int i = tl.x(); i < br.x(); i++)
|
||||||
for (int j = tl.y(); j < br.y(); j++)
|
for (int j = tl.y(); j < br.y(); j++)
|
||||||
tiles.append(FetchTile(QPoint(i, j), z.id()));
|
fetchTiles.append(TileLoader::Tile(QPoint(i, j), z.id()));
|
||||||
|
|
||||||
if (flags & Map::Block)
|
if (flags & Map::Block)
|
||||||
_tileLoader->loadTilesSync(tiles);
|
_tileLoader->loadTilesSync(fetchTiles);
|
||||||
else
|
else
|
||||||
_tileLoader->loadTilesAsync(tiles);
|
_tileLoader->loadTilesAsync(fetchTiles);
|
||||||
|
|
||||||
for (int i = 0; i < tiles.count(); i++) {
|
QList<FileTile> renderTiles;
|
||||||
FetchTile &t = tiles[i];
|
for (int i = 0; i < fetchTiles.count(); i++) {
|
||||||
|
const TileLoader::Tile &t = fetchTiles.at(i);
|
||||||
|
if (t.file().isNull())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QPixmap pm;
|
||||||
|
if (QPixmapCache::find(t.file(), &pm)) {
|
||||||
QPointF tp(t.xy().x() * ts.width(), t.xy().y() * ts.height());
|
QPointF tp(t.xy().x() * ts.width(), t.xy().y() * ts.height());
|
||||||
if (!t.pixmap().isNull()) {
|
drawTile(painter, pm, tp);
|
||||||
t.pixmap().setDevicePixelRatio(imageRatio());
|
} else
|
||||||
painter->drawPixmap(tp, t.pixmap());
|
renderTiles.append(FileTile(t.xy(), t.file()));
|
||||||
|
}
|
||||||
|
|
||||||
|
QFuture<void> future = QtConcurrent::map(renderTiles, &FileTile::load);
|
||||||
|
future.waitForFinished();
|
||||||
|
|
||||||
|
for (int i = 0; i < renderTiles.size(); i++) {
|
||||||
|
const FileTile &mt = renderTiles.at(i);
|
||||||
|
QPixmap pm(mt.pixmap());
|
||||||
|
if (pm.isNull())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QPixmapCache::insert(mt.file(), pm);
|
||||||
|
|
||||||
|
QPointF tp(mt.xy().x() * ts.width(), mt.xy().y() * ts.height());
|
||||||
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WMTSMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp)
|
||||||
|
{
|
||||||
|
pixmap.setDevicePixelRatio(imageRatio());
|
||||||
|
painter->drawPixmap(tp, pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF WMTSMap::ll2xy(const Coordinates &c)
|
QPointF WMTSMap::ll2xy(const Coordinates &c)
|
||||||
|
@ -53,6 +53,7 @@ private:
|
|||||||
qreal coordinatesRatio() const;
|
qreal coordinatesRatio() const;
|
||||||
qreal imageRatio() const;
|
qreal imageRatio() const;
|
||||||
void init();
|
void init();
|
||||||
|
void drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp);
|
||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
WMTS *_wmts;
|
WMTS *_wmts;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user