1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Limit the overzoom by the resulting tile size rather than number of levels

Huge sizes may cause broken rendering and cache ping-pong. Do not allow
resulting tile sizes > 4096x4096px.
This commit is contained in:
Martin Tůma 2023-12-18 20:32:00 +01:00
parent 4e1b696869
commit aa892f6c3f
3 changed files with 26 additions and 23 deletions

View File

@ -9,7 +9,7 @@
#include "osm.h"
#include "mbtilesmap.h"
#define MAX_OVERZOOM 3
#define MAX_TILE_SIZE 4096
#define META_TYPE(type) static_cast<QMetaType::Type>(type)
static RectC str2bounds(const QString &str)
@ -79,24 +79,15 @@ bool MBTilesMap::getZooms()
" WHERE zoom_level = %1 LIMIT 1").arg(i);
QSqlQuery query(sql, _db);
if (query.first())
_zooms.append(Zoom(i, i));
_zoomsBase.append(Zoom(i, i));
}
if (!_zooms.size()) {
if (!_zoomsBase.size()) {
_errorString = "Empty tile set";
return false;
}
if (_scalable) {
for (int i = _zooms.last().base + 1; i <= OSM::ZOOMS.max(); i++) {
Zoom z(i, _zooms.last().base);
if (z.z - z.base > MAX_OVERZOOM)
break;
_zooms.append(Zoom(i, _zooms.last().base));
}
}
_zi = _zooms.size() - 1;
_zi = _zoomsBase.size() - 1;
return true;
}
@ -114,7 +105,7 @@ bool MBTilesMap::getBounds()
} else {
qWarning("%s: missing bounds metadata", qPrintable(path()));
int z = _zooms.first().z;
int z = _zoomsBase.first().z;
QString sql = QString("SELECT min(tile_column), min(tile_row), "
"max(tile_column), max(tile_row) FROM tiles WHERE zoom_level = %1")
.arg(z);
@ -222,12 +213,12 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
}
getTileFormat();
if (!getTileSize())
return;
if (!getZooms())
return;
if (!getBounds())
return;
if (!getTileSize())
return;
getTilePixelRatio();
getName();
@ -243,10 +234,18 @@ void MBTilesMap::load(const Projection &in, const Projection &out,
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
_zooms = _zoomsBase;
if (_scalable) {
_scaledSize = _tileSize * deviceRatio;
_tileRatio = deviceRatio;
for (int i = _zooms.last().base + 1; i <= OSM::ZOOMS.max(); i++) {
Zoom z(i, _zooms.last().base);
if (_tileSize * _tileRatio * (1U<<(z.z - z.base)) > MAX_TILE_SIZE)
break;
_zooms.append(Zoom(i, _zooms.last().base));
}
}
_db.open();

View File

@ -146,7 +146,7 @@ private:
QString _name;
RectC _bounds;
QVector<Zoom> _zooms;
QVector<Zoom> _zooms, _zoomsBase;
int _zi;
int _tileSize;
qreal _mapRatio, _tileRatio;

View File

@ -8,7 +8,7 @@
#include "onlinemap.h"
#define MAX_OVERZOOM 3
#define MAX_TILE_SIZE 4096
OnlineMap::OnlineMap(const QString &fileName, const QString &name,
const QString &url, const Range &zooms, const RectC &bounds, qreal tileRatio,
@ -24,10 +24,7 @@ OnlineMap::OnlineMap(const QString &fileName, const QString &name,
_tileLoader->setHeaders(headers);
connect(_tileLoader, &TileLoader::finished, this, &OnlineMap::tilesLoaded);
if (_scalable) {
_baseZoom = _zooms.max();
_zooms.setMax(qMin(_zooms.max() + MAX_OVERZOOM, OSM::ZOOMS.max()));
}
_baseZoom = _zooms.max();
}
QRectF OnlineMap::bounds()
@ -87,10 +84,17 @@ void OnlineMap::load(const Projection &in, const Projection &out,
Q_UNUSED(out);
_mapRatio = hidpi ? deviceRatio : 1.0;
_zooms.setMax(_baseZoom);
if (_scalable) {
_scaledSize = _tileSize * deviceRatio;
_tileRatio = deviceRatio;
for (int i = _baseZoom + 1; i <= OSM::ZOOMS.max(); i++) {
if (_tileSize * _tileRatio * (1U<<(i - _baseZoom)) > MAX_TILE_SIZE)
break;
_zooms.setMax(i);
}
}
}
@ -168,7 +172,7 @@ void OnlineMap::cancelJobs(bool wait)
void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
{
int baseZoom = _scalable ? qMin(_baseZoom, _zoom) : _zoom;
int baseZoom = qMin(_baseZoom, _zoom);
unsigned overzoom = _zoom - baseZoom;
unsigned f = 1U<<overzoom;