1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 13:41:16 +01:00

Improved map index caching

This commit is contained in:
Martin Tůma 2018-03-09 18:56:54 +01:00
parent de05f5e64b
commit bc881836ac
2 changed files with 17 additions and 19 deletions

View File

@ -79,7 +79,8 @@ void Atlas::computeBounds()
BR(_maps.at(i))), QRectF(offsets.at(i), _maps.at(i)->bounds().size()))); BR(_maps.at(i))), QRectF(offsets.at(i), _maps.at(i)->bounds().size())));
} }
Atlas::Atlas(const QString &fileName, QObject *parent) : Map(parent) Atlas::Atlas(const QString &fileName, QObject *parent)
: Map(parent), _zoom(0), _mapIndex(-1), _valid(false)
{ {
QFileInfo fi(fileName); QFileInfo fi(fileName);
QByteArray ba; QByteArray ba;
@ -87,10 +88,7 @@ Atlas::Atlas(const QString &fileName, QObject *parent) : Map(parent)
Tar tar(fileName); Tar tar(fileName);
_valid = false;
_zoom = 0;
_name = fi.dir().dirName(); _name = fi.dir().dirName();
_ci = -1; _cz = -1;
if (suffix == "tar") { if (suffix == "tar") {
if (!tar.open()) { if (!tar.open()) {
@ -180,6 +178,7 @@ qreal Atlas::resolution(const QRectF &rect) const
int Atlas::zoomFit(const QSize &size, const RectC &br) int Atlas::zoomFit(const QSize &size, const RectC &br)
{ {
_zoom = 0; _zoom = 0;
_mapIndex = -1;
if (!br.isValid()) { if (!br.isValid()) {
_zoom = _zooms.size() - 1; _zoom = _zooms.size() - 1;
@ -209,12 +208,16 @@ int Atlas::zoomFit(const QSize &size, const RectC &br)
int Atlas::zoomIn() int Atlas::zoomIn()
{ {
_zoom = qMin(_zoom + 1, _zooms.size() - 1); _zoom = qMin(_zoom + 1, _zooms.size() - 1);
_mapIndex = -1;
return _zoom; return _zoom;
} }
int Atlas::zoomOut() int Atlas::zoomOut()
{ {
_zoom = qMax(_zoom - 1, 0); _zoom = qMax(_zoom - 1, 0);
_mapIndex = -1;
return _zoom; return _zoom;
} }
@ -222,26 +225,21 @@ QPointF Atlas::ll2xy(const Coordinates &c)
{ {
QPointF pp; QPointF pp;
if (_cz != _zoom) { if (_mapIndex >= 0)
_ci = -1; pp = _maps.at(_mapIndex)->ll2pp(c);
_cz = _zoom; if (_mapIndex < 0 || !_bounds.at(_mapIndex).first.contains(pp)) {
} _mapIndex = _zooms.at(_zoom).first;
if (_ci >= 0)
pp = _maps.at(_ci)->ll2pp(c);
if (_ci < 0 || !_bounds.at(_ci).first.contains(pp)) {
_ci = _zooms.at(_zoom).first;
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) { for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
pp = _maps.at(i)->ll2pp(c); pp = _maps.at(i)->ll2pp(c);
if (_bounds.at(i).first.contains(pp)) { if (_bounds.at(i).first.contains(pp)) {
_ci = i; _mapIndex = i;
break; break;
} }
} }
} }
QPointF p = _maps.at(_ci)->pp2xy(pp); QPointF p = _maps.at(_mapIndex)->pp2xy(pp);
return p + _bounds.at(_ci).second.topLeft(); return p + _bounds.at(_mapIndex).second.topLeft();
} }
Coordinates Atlas::xy2ll(const QPointF &p) Coordinates Atlas::xy2ll(const QPointF &p)

View File

@ -40,15 +40,15 @@ private:
void computeBounds(); void computeBounds();
QString _name; QString _name;
bool _valid;
QString _errorString;
QList<OfflineMap*> _maps; QList<OfflineMap*> _maps;
QVector<QPair<int, int> > _zooms; QVector<QPair<int, int> > _zooms;
QVector<QPair<QRectF, QRectF> > _bounds; QVector<QPair<QRectF, QRectF> > _bounds;
int _zoom; int _zoom;
int _mapIndex;
int _ci, _cz; bool _valid;
QString _errorString;
}; };
#endif // ATLAS_H #endif // ATLAS_H