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
d4b731aeaf
commit
5f76427ba4
@ -118,11 +118,18 @@ qreal OnlineMap::tileSize() const
|
|||||||
return (_tileSize / coordinatesRatio());
|
return (_tileSize / coordinatesRatio());
|
||||||
}
|
}
|
||||||
|
|
||||||
QPoint OnlineMap::tileCoordinates(int x, int y, int zoom)
|
QPoint OnlineMap::tileCoordinates(int x, int y, int zoom) const
|
||||||
{
|
{
|
||||||
return QPoint(x, _invertY ? (1<<zoom) - y - 1 : y);
|
return QPoint(x, _invertY ? (1<<zoom) - y - 1 : y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPointF OnlineMap::tilePos(const QPointF &tl, const QPoint &tc,
|
||||||
|
const QPoint &tile, unsigned overzoom) const
|
||||||
|
{
|
||||||
|
return QPointF(tl.x() + ((tc.x() - tile.x()) << overzoom) * tileSize(),
|
||||||
|
tl.y() + ((tc.y() - tile.y()) << overzoom) * tileSize());
|
||||||
|
}
|
||||||
|
|
||||||
bool OnlineMap::isRunning(const QString &key) const
|
bool OnlineMap::isRunning(const QString &key) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _jobs.size(); i++) {
|
for (int i = 0; i < _jobs.size(); i++) {
|
||||||
@ -174,14 +181,14 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
{
|
{
|
||||||
int baseZoom = qMin(_baseZoom, _zoom);
|
int baseZoom = qMin(_baseZoom, _zoom);
|
||||||
unsigned overzoom = _zoom - baseZoom;
|
unsigned overzoom = _zoom - baseZoom;
|
||||||
unsigned f = 1U<<overzoom;
|
|
||||||
|
|
||||||
qreal scale = OSM::zoom2scale(baseZoom, _tileSize * f);
|
qreal scale = OSM::zoom2scale(baseZoom, _tileSize << overzoom);
|
||||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||||
-rect.topLeft().y() * scale) * coordinatesRatio(), baseZoom);
|
-rect.topLeft().y() * scale) * coordinatesRatio(), baseZoom);
|
||||||
Coordinates ctl(OSM::tile2ll(tile, baseZoom));
|
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());
|
||||||
|
unsigned f = 1U<<overzoom;
|
||||||
int width = ceil(s.width() / (tileSize() * f));
|
int width = ceil(s.width() / (tileSize() * f));
|
||||||
int height = ceil(s.height() / (tileSize() * f));
|
int height = ceil(s.height() / (tileSize() * f));
|
||||||
|
|
||||||
@ -213,8 +220,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(), baseZoom));
|
QPoint tc(tileCoordinates(t.xy().x(), t.xy().y(), baseZoom));
|
||||||
QPointF tp(tl.x() + (tc.x() - tile.x()) * tileSize() * f,
|
QPointF tp(tilePos(tl, tc, tile, overzoom));
|
||||||
tl.y() + (tc.y() - tile.y()) * tileSize() * f);
|
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
} else
|
} else
|
||||||
renderTiles.append(OnlineMapTile(t.xy(), t.file(), _zoom, overzoom,
|
renderTiles.append(OnlineMapTile(t.xy(), t.file(), _zoom, overzoom,
|
||||||
@ -236,8 +242,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(), baseZoom));
|
QPoint tc(tileCoordinates(mt.xy().x(), mt.xy().y(), baseZoom));
|
||||||
QPointF tp(tl.x() + (tc.x() - tile.x()) * tileSize() * f,
|
QPointF tp(tilePos(tl, tc, tile, overzoom));
|
||||||
tl.y() + (tc.y() - tile.y()) * tileSize() * f);
|
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
@ -115,7 +115,9 @@ private:
|
|||||||
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);
|
QPoint tileCoordinates(int x, int y, int zoom) const;
|
||||||
|
QPointF tilePos(const QPointF &tl, const QPoint &tc, const QPoint &tile,
|
||||||
|
unsigned overzoom) const;
|
||||||
void drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp);
|
void drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp);
|
||||||
bool isRunning(const QString &key) const;
|
bool isRunning(const QString &key) const;
|
||||||
void runJob(OnlineMapJob *job);
|
void runJob(OnlineMapJob *job);
|
||||||
|
Loading…
Reference in New Issue
Block a user