1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 06:43:22 +02: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);
const Zoom &z = _zooms.at(_zoom);
qreal scale = OSM::zoom2scale(z.zoom, z.tileSize);
QRectF b(bounds());
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
-rect.topLeft().y() * scale) * _mapRatio, z.zoom);
QPointF tl(floor(rect.left() / tileSize())
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
qMin(rect.bottom() - tl.y(), b.height()));
Coordinates ctl(OSM::tile2ll(tile, z.zoom));
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
int width = ceil(s.width() / tileSize());
int height = ceil(s.height() / tileSize());
QList<RenderTile> tiles;
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());
if (QPixmapCache::find(key, &pm)) {
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x())
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
* tileSize());
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
tl.y() + (t.y() - tile.y()) * tileSize());
drawTile(painter, pm, tp);
} else {
} else
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);
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x())
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y())
* tileSize());
QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize(),
tl.y() + (mt.xy().y() - tile.y()) * tileSize());
drawTile(painter, pm, tp);
}
}

View File

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

View File

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

View File

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