mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Code cleanup
This commit is contained in:
parent
5fcc27c176
commit
c1c8f6303c
@ -15,7 +15,7 @@ OnlineMap::OnlineMap(const QString &fileName, const QString &name,
|
|||||||
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), _base(0), _mapRatio(1.0),
|
_zoom(_zooms.max()), _tileSize(tileSize), _baseZoom(0), _mapRatio(1.0),
|
||||||
_tileRatio(tileRatio), _scalable(scalable), _scaledSize(0), _invertY(invertY)
|
_tileRatio(tileRatio), _scalable(scalable), _scaledSize(0), _invertY(invertY)
|
||||||
{
|
{
|
||||||
_tileLoader = new TileLoader(QDir(ProgramPaths::tilesDir()).filePath(_name),
|
_tileLoader = new TileLoader(QDir(ProgramPaths::tilesDir()).filePath(_name),
|
||||||
@ -25,7 +25,7 @@ OnlineMap::OnlineMap(const QString &fileName, const QString &name,
|
|||||||
connect(_tileLoader, &TileLoader::finished, this, &OnlineMap::tilesLoaded);
|
connect(_tileLoader, &TileLoader::finished, this, &OnlineMap::tilesLoaded);
|
||||||
|
|
||||||
if (_scalable) {
|
if (_scalable) {
|
||||||
_base = _zooms.max();
|
_baseZoom = _zooms.max();
|
||||||
_zooms.setMax(qMin(_zooms.max() + MAX_OVERZOOM, OSM::ZOOMS.max()));
|
_zooms.setMax(qMin(_zooms.max() + MAX_OVERZOOM, OSM::ZOOMS.max()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,14 +168,14 @@ void OnlineMap::cancelJobs(bool wait)
|
|||||||
|
|
||||||
void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||||
{
|
{
|
||||||
int base = _scalable ? qMin(_base, _zoom) : _zoom;
|
int baseZoom = _scalable ? qMin(_baseZoom, _zoom) : _zoom;
|
||||||
unsigned overzoom = _zoom - base;
|
unsigned overzoom = _zoom - baseZoom;
|
||||||
unsigned f = 1U<<overzoom;
|
unsigned f = 1U<<overzoom;
|
||||||
|
|
||||||
qreal scale = OSM::zoom2scale(base, _tileSize * f);
|
qreal scale = OSM::zoom2scale(baseZoom, _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(), base);
|
-rect.topLeft().y() * scale) * coordinatesRatio(), baseZoom);
|
||||||
Coordinates ctl(OSM::tile2ll(tile, base));
|
Coordinates ctl(OSM::tile2ll(tile, baseZoom));
|
||||||
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() * f));
|
int width = ceil(s.width() / (tileSize() * f));
|
||||||
@ -185,8 +185,8 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
fetchTiles.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++) {
|
||||||
QPoint tc(tileCoordinates(tile.x() + i, tile.y() + j, base));
|
QPoint tc(tileCoordinates(tile.x() + i, tile.y() + j, baseZoom));
|
||||||
fetchTiles.append(TileLoader::Tile(tc, base));
|
fetchTiles.append(TileLoader::Tile(tc, baseZoom));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +208,7 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
|
|
||||||
QPixmap pm;
|
QPixmap pm;
|
||||||
if (QPixmapCache::find(key, &pm)) {
|
if (QPixmapCache::find(key, &pm)) {
|
||||||
QPoint tc(tileCoordinates(t.xy().x(), t.xy().y(), base));
|
QPoint tc(tileCoordinates(t.xy().x(), t.xy().y(), baseZoom));
|
||||||
QPointF tp(tl.x() + (tc.x() - tile.x()) * tileSize() * f,
|
QPointF tp(tl.x() + (tc.x() - tile.x()) * tileSize() * f,
|
||||||
tl.y() + (tc.y() - tile.y()) * tileSize() * f);
|
tl.y() + (tc.y() - tile.y()) * tileSize() * f);
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
@ -231,7 +231,7 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
|
|
||||||
QPixmapCache::insert(mt.key(), pm);
|
QPixmapCache::insert(mt.key(), pm);
|
||||||
|
|
||||||
QPoint tc(tileCoordinates(mt.xy().x(), mt.xy().y(), base));
|
QPoint tc(tileCoordinates(mt.xy().x(), mt.xy().y(), baseZoom));
|
||||||
QPointF tp(tl.x() + (tc.x() - tile.x()) * tileSize() * f,
|
QPointF tp(tl.x() + (tc.x() - tile.x()) * tileSize() * f,
|
||||||
tl.y() + (tc.y() - tile.y()) * tileSize() * f);
|
tl.y() + (tc.y() - tile.y()) * tileSize() * f);
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
|
@ -128,7 +128,7 @@ private:
|
|||||||
RectC _bounds;
|
RectC _bounds;
|
||||||
int _zoom;
|
int _zoom;
|
||||||
int _tileSize;
|
int _tileSize;
|
||||||
int _base;
|
int _baseZoom;
|
||||||
qreal _mapRatio, _tileRatio;
|
qreal _mapRatio, _tileRatio;
|
||||||
bool _scalable;
|
bool _scalable;
|
||||||
int _scaledSize;
|
int _scaledSize;
|
||||||
|
Loading…
Reference in New Issue
Block a user