diff --git a/src/map/atlas.cpp b/src/map/atlas.cpp index 6a317676..33142a73 100644 --- a/src/map/atlas.cpp +++ b/src/map/atlas.cpp @@ -79,7 +79,8 @@ void Atlas::computeBounds() 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); QByteArray ba; @@ -87,10 +88,7 @@ Atlas::Atlas(const QString &fileName, QObject *parent) : Map(parent) Tar tar(fileName); - _valid = false; - _zoom = 0; _name = fi.dir().dirName(); - _ci = -1; _cz = -1; if (suffix == "tar") { if (!tar.open()) { @@ -180,6 +178,7 @@ qreal Atlas::resolution(const QRectF &rect) const int Atlas::zoomFit(const QSize &size, const RectC &br) { _zoom = 0; + _mapIndex = -1; if (!br.isValid()) { _zoom = _zooms.size() - 1; @@ -209,12 +208,16 @@ int Atlas::zoomFit(const QSize &size, const RectC &br) int Atlas::zoomIn() { _zoom = qMin(_zoom + 1, _zooms.size() - 1); + _mapIndex = -1; + return _zoom; } int Atlas::zoomOut() { _zoom = qMax(_zoom - 1, 0); + _mapIndex = -1; + return _zoom; } @@ -222,26 +225,21 @@ QPointF Atlas::ll2xy(const Coordinates &c) { QPointF pp; - if (_cz != _zoom) { - _ci = -1; - _cz = _zoom; - } - - if (_ci >= 0) - pp = _maps.at(_ci)->ll2pp(c); - if (_ci < 0 || !_bounds.at(_ci).first.contains(pp)) { - _ci = _zooms.at(_zoom).first; + if (_mapIndex >= 0) + pp = _maps.at(_mapIndex)->ll2pp(c); + if (_mapIndex < 0 || !_bounds.at(_mapIndex).first.contains(pp)) { + _mapIndex = _zooms.at(_zoom).first; for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) { pp = _maps.at(i)->ll2pp(c); if (_bounds.at(i).first.contains(pp)) { - _ci = i; + _mapIndex = i; break; } } } - QPointF p = _maps.at(_ci)->pp2xy(pp); - return p + _bounds.at(_ci).second.topLeft(); + QPointF p = _maps.at(_mapIndex)->pp2xy(pp); + return p + _bounds.at(_mapIndex).second.topLeft(); } Coordinates Atlas::xy2ll(const QPointF &p) diff --git a/src/map/atlas.h b/src/map/atlas.h index f21a8621..ba4ddc60 100644 --- a/src/map/atlas.h +++ b/src/map/atlas.h @@ -40,15 +40,15 @@ private: void computeBounds(); QString _name; - bool _valid; - QString _errorString; QList _maps; QVector > _zooms; QVector > _bounds; int _zoom; + int _mapIndex; - int _ci, _cz; + bool _valid; + QString _errorString; }; #endif // ATLAS_H