1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Fixed map bounds limiting

This commit is contained in:
Martin Tůma 2023-11-18 23:55:58 +01:00
parent aedbc99a6c
commit 95d354f10c
4 changed files with 32 additions and 68 deletions

View File

@ -347,20 +347,14 @@ void AQMMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
Q_UNUSED(flags); Q_UNUSED(flags);
const Zoom &z = _zooms.at(_zoom); const Zoom &z = _zooms.at(_zoom);
qreal scale = OSM::zoom2scale(z.zoom, z.tileSize); qreal scale = OSM::zoom2scale(z.zoom, z.tileSize);
QRectF b(bounds());
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale, QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
-rect.topLeft().y() * scale) * _mapRatio, z.zoom); -rect.topLeft().y() * scale) * _mapRatio, z.zoom);
QPointF tl(floor(rect.left() / tileSize()) Coordinates ctl(OSM::tile2ll(tile, z.zoom));
* tileSize(), floor(rect.top() / tileSize()) * tileSize()); QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
qMin(rect.bottom() - tl.y(), b.height()));
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<RenderTile> tiles;
for (int i = 0; i < width; i++) { for (int i = 0; i < width; i++) {
@ -371,13 +365,11 @@ void AQMMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
+ QString::number(t.x()) + "_" + QString::number(t.y()); + QString::number(t.x()) + "_" + QString::number(t.y());
if (QPixmapCache::find(key, &pm)) { if (QPixmapCache::find(key, &pm)) {
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x()) QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y()) tl.y() + (t.y() - tile.y()) * tileSize());
* tileSize());
drawTile(painter, pm, tp); drawTile(painter, pm, tp);
} else { } else
tiles.append(RenderTile(t, tileData(t), key)); tiles.append(RenderTile(t, tileData(t), key));
}
} }
} }
@ -392,9 +384,8 @@ void AQMMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
QPixmapCache::insert(mt.key(), pm); QPixmapCache::insert(mt.key(), pm);
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x()) QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize(),
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y()) tl.y() + (mt.xy().y() - tile.y()) * tileSize());
* tileSize());
drawTile(painter, pm, tp); drawTile(painter, pm, tp);
} }
} }

View File

@ -243,20 +243,14 @@ void GEMFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
Q_UNUSED(flags); Q_UNUSED(flags);
const Zoom &z = _zooms.at(_zi); const Zoom &z = _zooms.at(_zi);
qreal scale = OSM::zoom2scale(z.level, _tileSize); qreal scale = OSM::zoom2scale(z.level, _tileSize);
QRectF b(bounds());
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale, QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
-rect.topLeft().y() * scale) * _mapRatio, z.level); -rect.topLeft().y() * scale) * _mapRatio, z.level);
QPointF tl(floor(rect.left() / tileSize()) Coordinates ctl(OSM::tile2ll(tile, z.level));
* tileSize(), floor(rect.top() / tileSize()) * tileSize()); QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
qMin(rect.bottom() - tl.y(), b.height()));
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<RenderTile> tiles;
for (int i = 0; i < width; i++) { for (int i = 0; i < width; i++) {
@ -267,13 +261,11 @@ void GEMFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
+ QString::number(t.x()) + "_" + QString::number(t.y()); + QString::number(t.x()) + "_" + QString::number(t.y());
if (QPixmapCache::find(key, &pm)) { if (QPixmapCache::find(key, &pm)) {
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x()) QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y()) tl.y() + (t.y() - tile.y()) * tileSize());
* tileSize());
drawTile(painter, pm, tp); drawTile(painter, pm, tp);
} else { } else
tiles.append(RenderTile(t, tileData(t), key)); tiles.append(RenderTile(t, tileData(t), key));
}
} }
} }
@ -288,9 +280,8 @@ void GEMFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
QPixmapCache::insert(mt.key(), pm); QPixmapCache::insert(mt.key(), pm);
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x()) QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize(),
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y()) tl.y() + (mt.xy().y() - tile.y())* tileSize());
* tileSize());
drawTile(painter, pm, tp); drawTile(painter, pm, tp);
} }
} }

View File

@ -238,20 +238,14 @@ void OsmdroidMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
{ {
Q_UNUSED(flags); Q_UNUSED(flags);
qreal scale = OSM::zoom2scale(_zoom, _tileSize); qreal scale = OSM::zoom2scale(_zoom, _tileSize);
QRectF b(bounds());
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale, QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
-rect.topLeft().y() * scale) * _mapRatio, _zoom); -rect.topLeft().y() * scale) * _mapRatio, _zoom);
QPointF tl(floor(rect.left() / tileSize()) Coordinates ctl(OSM::tile2ll(tile, _zoom));
* tileSize(), floor(rect.top() / tileSize()) * tileSize()); QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
qMin(rect.bottom() - tl.y(), b.height()));
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<RenderTile> tiles;
for (int i = 0; i < width; i++) { for (int i = 0; i < width; i++) {
@ -262,13 +256,11 @@ void OsmdroidMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
+ QString::number(t.x()) + "_" + QString::number(t.y()); + QString::number(t.x()) + "_" + QString::number(t.y());
if (QPixmapCache::find(key, &pm)) { if (QPixmapCache::find(key, &pm)) {
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x()) QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y()) tl.y() + (t.y() - tile.y()) * tileSize());
* tileSize());
drawTile(painter, pm, tp); drawTile(painter, pm, tp);
} else { } else
tiles.append(RenderTile(t, tileData(_zoom, t), key)); tiles.append(RenderTile(t, tileData(_zoom, t), key));
}
} }
} }
@ -283,9 +275,8 @@ void OsmdroidMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
QPixmapCache::insert(mt.key(), pm); QPixmapCache::insert(mt.key(), pm);
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x()) QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize(),
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y()) tl.y() + (mt.xy().y() - tile.y()) * tileSize());
* tileSize());
drawTile(painter, pm, tp); drawTile(painter, pm, tp);
} }
} }

View File

@ -185,20 +185,14 @@ void SqliteMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
{ {
Q_UNUSED(flags); Q_UNUSED(flags);
qreal scale = OSM::zoom2scale(_zoom, _tileSize); qreal scale = OSM::zoom2scale(_zoom, _tileSize);
QRectF b(bounds());
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale, QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
-rect.topLeft().y() * scale) * _mapRatio, _zoom); -rect.topLeft().y() * scale) * _mapRatio, _zoom);
QPointF tl(floor(rect.left() / tileSize()) Coordinates ctl(OSM::tile2ll(tile, _zoom));
* tileSize(), floor(rect.top() / tileSize()) * tileSize()); QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
qMin(rect.bottom() - tl.y(), b.height()));
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<RenderTile> tiles;
for (int i = 0; i < width; i++) { for (int i = 0; i < width; i++) {
@ -209,13 +203,11 @@ void SqliteMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
+ QString::number(t.x()) + "_" + QString::number(t.y()); + QString::number(t.x()) + "_" + QString::number(t.y());
if (QPixmapCache::find(key, &pm)) { if (QPixmapCache::find(key, &pm)) {
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x()) QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y()) tl.y() + (t.y() - tile.y()) * tileSize());
* tileSize());
drawTile(painter, pm, tp); drawTile(painter, pm, tp);
} else { } else
tiles.append(RenderTile(t, tileData(_zoom, t), key)); tiles.append(RenderTile(t, tileData(_zoom, t), key));
}
} }
} }
@ -230,9 +222,8 @@ void SqliteMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
QPixmapCache::insert(mt.key(), pm); QPixmapCache::insert(mt.key(), pm);
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x()) QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize(),
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y()) tl.y() + (mt.xy().y() - tile.y()) * tileSize());
* tileSize());
drawTile(painter, pm, tp); drawTile(painter, pm, tp);
} }
} }