From 2bf66ea9128181a7dfec2b0dc7668bc7660341a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Mon, 20 Mar 2017 09:25:05 +0100 Subject: [PATCH] Tile loading code cleanup --- src/onlinemap.cpp | 38 ++++++++++++++------------------------ src/tile.h | 2 -- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/onlinemap.cpp b/src/onlinemap.cpp index 5b6c114d..2fc10d45 100644 --- a/src/onlinemap.cpp +++ b/src/onlinemap.cpp @@ -12,6 +12,7 @@ #define ZOOM_MAX 18 #define ZOOM_MIN 3 +#define TILE_SIZE 256 static QPoint mercator2tile(const QPointF &m, int z) { @@ -23,19 +24,9 @@ static QPoint mercator2tile(const QPointF &m, int z) return tile; } -static QPointF tile2mercator(const QPoint &tile, int z) -{ - QPointF m; - - m.setX(((360.0 * tile.x()) / (qreal)(1< &list) void OnlineMap::fillTile(Tile &tile) { - tile.pixmap() = QPixmap(Tile::size(), Tile::size()); + tile.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE); tile.pixmap().fill(); } @@ -178,7 +169,7 @@ QRectF OnlineMap::bounds() const qreal OnlineMap::zoomFit(const QSize &size, const QRectF &br) { if (br.isNull()) - _scale = ((360.0/(qreal)(1< tiles; QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y()); - for (int i = 0; i < ceil(s.width() / Tile::size()); i++) - for (int j = 0; j < ceil(s.height() / Tile::size()); j++) + for (int i = 0; i < ceil(s.width() / TILE_SIZE); i++) + for (int j = 0; j < ceil(s.height() / TILE_SIZE); j++) tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), zoom)); if (_block) @@ -236,8 +226,8 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect) for (int i = 0; i < tiles.count(); i++) { Tile &t = tiles[i]; - QPoint tp(tl.x() + (t.xy().x() - tile.x()) * Tile::size(), - tl.y() + (t.xy().y() - tile.y()) * Tile::size()); + QPoint tp(tl.x() + (t.xy().x() - tile.x()) * TILE_SIZE, + tl.y() + (t.xy().y() - tile.y()) * TILE_SIZE); painter->drawPixmap(tp, t.pixmap()); } } diff --git a/src/tile.h b/src/tile.h index 3cf5082c..383d2e31 100644 --- a/src/tile.h +++ b/src/tile.h @@ -14,8 +14,6 @@ public: const QPoint& xy() const {return _xy;} QPixmap& pixmap() {return _pixmap;} - static int size() {return 256;} - private: int _zoom; QPoint _xy;