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:
parent
4e1b696869
commit
aa892f6c3f
@ -9,7 +9,7 @@
|
|||||||
#include "osm.h"
|
#include "osm.h"
|
||||||
#include "mbtilesmap.h"
|
#include "mbtilesmap.h"
|
||||||
|
|
||||||
#define MAX_OVERZOOM 3
|
#define MAX_TILE_SIZE 4096
|
||||||
#define META_TYPE(type) static_cast<QMetaType::Type>(type)
|
#define META_TYPE(type) static_cast<QMetaType::Type>(type)
|
||||||
|
|
||||||
static RectC str2bounds(const QString &str)
|
static RectC str2bounds(const QString &str)
|
||||||
@ -79,24 +79,15 @@ bool MBTilesMap::getZooms()
|
|||||||
" WHERE zoom_level = %1 LIMIT 1").arg(i);
|
" WHERE zoom_level = %1 LIMIT 1").arg(i);
|
||||||
QSqlQuery query(sql, _db);
|
QSqlQuery query(sql, _db);
|
||||||
if (query.first())
|
if (query.first())
|
||||||
_zooms.append(Zoom(i, i));
|
_zoomsBase.append(Zoom(i, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_zooms.size()) {
|
if (!_zoomsBase.size()) {
|
||||||
_errorString = "Empty tile set";
|
_errorString = "Empty tile set";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_scalable) {
|
_zi = _zoomsBase.size() - 1;
|
||||||
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;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -114,7 +105,7 @@ bool MBTilesMap::getBounds()
|
|||||||
} else {
|
} else {
|
||||||
qWarning("%s: missing bounds metadata", qPrintable(path()));
|
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), "
|
QString sql = QString("SELECT min(tile_column), min(tile_row), "
|
||||||
"max(tile_column), max(tile_row) FROM tiles WHERE zoom_level = %1")
|
"max(tile_column), max(tile_row) FROM tiles WHERE zoom_level = %1")
|
||||||
.arg(z);
|
.arg(z);
|
||||||
@ -222,12 +213,12 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTileFormat();
|
getTileFormat();
|
||||||
|
if (!getTileSize())
|
||||||
|
return;
|
||||||
if (!getZooms())
|
if (!getZooms())
|
||||||
return;
|
return;
|
||||||
if (!getBounds())
|
if (!getBounds())
|
||||||
return;
|
return;
|
||||||
if (!getTileSize())
|
|
||||||
return;
|
|
||||||
getTilePixelRatio();
|
getTilePixelRatio();
|
||||||
getName();
|
getName();
|
||||||
|
|
||||||
@ -243,10 +234,18 @@ void MBTilesMap::load(const Projection &in, const Projection &out,
|
|||||||
Q_UNUSED(out);
|
Q_UNUSED(out);
|
||||||
|
|
||||||
_mapRatio = hidpi ? deviceRatio : 1.0;
|
_mapRatio = hidpi ? deviceRatio : 1.0;
|
||||||
|
_zooms = _zoomsBase;
|
||||||
|
|
||||||
if (_scalable) {
|
if (_scalable) {
|
||||||
_scaledSize = _tileSize * deviceRatio;
|
_scaledSize = _tileSize * deviceRatio;
|
||||||
_tileRatio = 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();
|
_db.open();
|
||||||
|
@ -146,7 +146,7 @@ private:
|
|||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
RectC _bounds;
|
RectC _bounds;
|
||||||
QVector<Zoom> _zooms;
|
QVector<Zoom> _zooms, _zoomsBase;
|
||||||
int _zi;
|
int _zi;
|
||||||
int _tileSize;
|
int _tileSize;
|
||||||
qreal _mapRatio, _tileRatio;
|
qreal _mapRatio, _tileRatio;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "onlinemap.h"
|
#include "onlinemap.h"
|
||||||
|
|
||||||
|
|
||||||
#define MAX_OVERZOOM 3
|
#define MAX_TILE_SIZE 4096
|
||||||
|
|
||||||
OnlineMap::OnlineMap(const QString &fileName, const QString &name,
|
OnlineMap::OnlineMap(const QString &fileName, const QString &name,
|
||||||
const QString &url, const Range &zooms, const RectC &bounds, qreal tileRatio,
|
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);
|
_tileLoader->setHeaders(headers);
|
||||||
connect(_tileLoader, &TileLoader::finished, this, &OnlineMap::tilesLoaded);
|
connect(_tileLoader, &TileLoader::finished, this, &OnlineMap::tilesLoaded);
|
||||||
|
|
||||||
if (_scalable) {
|
_baseZoom = _zooms.max();
|
||||||
_baseZoom = _zooms.max();
|
|
||||||
_zooms.setMax(qMin(_zooms.max() + MAX_OVERZOOM, OSM::ZOOMS.max()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF OnlineMap::bounds()
|
QRectF OnlineMap::bounds()
|
||||||
@ -87,10 +84,17 @@ void OnlineMap::load(const Projection &in, const Projection &out,
|
|||||||
Q_UNUSED(out);
|
Q_UNUSED(out);
|
||||||
|
|
||||||
_mapRatio = hidpi ? deviceRatio : 1.0;
|
_mapRatio = hidpi ? deviceRatio : 1.0;
|
||||||
|
_zooms.setMax(_baseZoom);
|
||||||
|
|
||||||
if (_scalable) {
|
if (_scalable) {
|
||||||
_scaledSize = _tileSize * deviceRatio;
|
_scaledSize = _tileSize * deviceRatio;
|
||||||
_tileRatio = 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)
|
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 overzoom = _zoom - baseZoom;
|
||||||
unsigned f = 1U<<overzoom;
|
unsigned f = 1U<<overzoom;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user