From 92e772a02b499bd23e3866d9217e9eb20727513a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 3 Dec 2017 10:17:29 +0100 Subject: [PATCH] Fixed some corner case map drawing issues --- src/GUI/mapview.cpp | 1 + src/map/offlinemap.cpp | 11 ++++++++--- src/map/onlinemap.cpp | 14 +++++++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index 60a32a04..4d10a663 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -274,6 +274,7 @@ void MapView::setMap(Map *map) _map = map; _map->load(); + _map->setBackgroundColor(_backgroundColor); connect(_map, SIGNAL(loaded()), this, SLOT(reloadMap())); digitalZoom(0); diff --git a/src/map/offlinemap.cpp b/src/map/offlinemap.cpp index 97e3499d..0491030b 100644 --- a/src/map/offlinemap.cpp +++ b/src/map/offlinemap.cpp @@ -622,12 +622,17 @@ void OfflineMap::drawImage(QPainter *painter, const QRectF &rect) void OfflineMap::draw(QPainter *painter, const QRectF &rect) { + QRectF ir = rect.intersected(bounds()); + + if (ir != rect) + painter->fillRect(rect, _backgroundColor); + if (_ozf.isOpen()) - drawOZF(painter, rect); + drawOZF(painter, ir); else if (_tileSize.isValid()) - drawTiled(painter, rect); + drawTiled(painter, ir); else - drawImage(painter, rect); + drawImage(painter, ir); } QPointF OfflineMap::ll2xy(const Coordinates &c) diff --git a/src/map/onlinemap.cpp b/src/map/onlinemap.cpp index 8f10df9f..ccfd0e7e 100644 --- a/src/map/onlinemap.cpp +++ b/src/map/onlinemap.cpp @@ -228,14 +228,18 @@ qreal OnlineMap::zoomOut() void OnlineMap::draw(QPainter *painter, const QRectF &rect) { qreal scale = zoom2scale(_zoom); + QRectF ir = rect.intersected(bounds()); - QPoint tile = mercator2tile(QPointF(rect.topLeft().x() * scale, - -rect.topLeft().y() * scale), _zoom); - QPoint tl = QPoint((int)floor(rect.left() / (qreal)TILE_SIZE) - * TILE_SIZE, (int)floor(rect.top() / TILE_SIZE) * TILE_SIZE); + if (ir != rect) + painter->fillRect(rect, _backgroundColor); + + QPoint tile = mercator2tile(QPointF(ir.topLeft().x() * scale, + -ir.topLeft().y() * scale), _zoom); + QPoint tl = QPoint((int)floor(ir.left() / (qreal)TILE_SIZE) + * TILE_SIZE, (int)floor(ir.top() / TILE_SIZE) * TILE_SIZE); QList tiles; - QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y()); + QSizeF s(ir.right() - tl.x(), ir.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++) tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));