mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 11:45:53 +01:00
Fixed atlas ll2xy() caching
This commit is contained in:
parent
b500031713
commit
0aedec66c4
@ -118,6 +118,7 @@ Atlas::Atlas(const QString &fileName, QObject *parent) : Map(parent)
|
||||
_valid = false;
|
||||
_zoom = 0;
|
||||
_name = fi.dir().dirName();
|
||||
_ci = -1; _cz = -1;
|
||||
|
||||
if (!isAtlas(tar, fileName))
|
||||
return;
|
||||
@ -233,35 +234,33 @@ qreal Atlas::zoomOut()
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
QPointF Atlas::ll2xy(const Coordinates &c) const
|
||||
QPointF Atlas::ll2xy(const Coordinates &c)
|
||||
{
|
||||
static int idx = -1;
|
||||
static int zoom = -1;
|
||||
QPointF pp;
|
||||
|
||||
if (zoom != _zoom) {
|
||||
idx = -1;
|
||||
zoom = _zoom;
|
||||
if (_cz != _zoom) {
|
||||
_ci = -1;
|
||||
_cz = _zoom;
|
||||
}
|
||||
|
||||
if (idx >= 0)
|
||||
pp = _maps.at(idx)->ll2pp(c);
|
||||
if (idx < 0 || !_bounds.at(idx).first.contains(pp)) {
|
||||
idx = _zooms.at(zoom).first;
|
||||
for (int i = _zooms.at(zoom).first; i <= _zooms.at(zoom).second; i++) {
|
||||
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++) {
|
||||
pp = _maps.at(i)->ll2pp(c);
|
||||
if (_bounds.at(i).first.contains(pp)) {
|
||||
idx = i;
|
||||
_ci = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QPointF p = _maps.at(idx)->pp2xy(pp);
|
||||
return p + _bounds.at(idx).second.topLeft();
|
||||
QPointF p = _maps.at(_ci)->pp2xy(pp);
|
||||
return p + _bounds.at(_ci).second.topLeft();
|
||||
}
|
||||
|
||||
Coordinates Atlas::xy2ll(const QPointF &p) const
|
||||
Coordinates Atlas::xy2ll(const QPointF &p)
|
||||
{
|
||||
int idx = _zooms.at(_zoom).first;
|
||||
|
||||
|
@ -24,8 +24,8 @@ public:
|
||||
qreal zoomIn();
|
||||
qreal zoomOut();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c) const;
|
||||
Coordinates xy2ll(const QPointF &p) const;
|
||||
QPointF ll2xy(const Coordinates &c);
|
||||
Coordinates xy2ll(const QPointF &p);
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect);
|
||||
|
||||
@ -48,6 +48,8 @@ private:
|
||||
QVector<QPair<int, int> > _zooms;
|
||||
QVector<QPair<QRectF, QRectF> > _bounds;
|
||||
int _zoom;
|
||||
|
||||
int _ci, _cz;
|
||||
};
|
||||
|
||||
#endif // ATLAS_H
|
||||
|
@ -64,13 +64,13 @@ void EmptyMap::draw(QPainter *painter, const QRectF &rect)
|
||||
painter->fillRect(rect, Qt::white);
|
||||
}
|
||||
|
||||
QPointF EmptyMap::ll2xy(const Coordinates &c) const
|
||||
QPointF EmptyMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
QPointF m = Mercator().ll2xy(c);
|
||||
return QPointF(m.x() / _scale, m.y() / -_scale);
|
||||
}
|
||||
|
||||
Coordinates EmptyMap::xy2ll(const QPointF &p) const
|
||||
Coordinates EmptyMap::xy2ll(const QPointF &p)
|
||||
{
|
||||
QPointF m(p.x() * _scale, -p.y() * _scale);
|
||||
return Mercator().xy2ll(m);
|
||||
|
@ -20,8 +20,8 @@ public:
|
||||
qreal zoomIn();
|
||||
qreal zoomOut();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c) const;
|
||||
Coordinates xy2ll(const QPointF &p) const;
|
||||
QPointF ll2xy(const Coordinates &c);
|
||||
Coordinates xy2ll(const QPointF &p);
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect);
|
||||
|
||||
|
@ -25,8 +25,8 @@ public:
|
||||
virtual qreal zoomIn() = 0;
|
||||
virtual qreal zoomOut() = 0;
|
||||
|
||||
virtual QPointF ll2xy(const Coordinates &c) const = 0;
|
||||
virtual Coordinates xy2ll(const QPointF &p) const = 0;
|
||||
virtual QPointF ll2xy(const Coordinates &c) = 0;
|
||||
virtual Coordinates xy2ll(const QPointF &p) = 0;
|
||||
|
||||
virtual void draw(QPainter *painter, const QRectF &rect) = 0;
|
||||
|
||||
|
@ -31,9 +31,9 @@ public:
|
||||
qreal zoomIn() {return 1.0;}
|
||||
qreal zoomOut() {return 1.0;}
|
||||
|
||||
QPointF ll2xy(const Coordinates &c) const
|
||||
QPointF ll2xy(const Coordinates &c)
|
||||
{return _transform.map(_projection->ll2xy(c));}
|
||||
Coordinates xy2ll(const QPointF &p) const
|
||||
Coordinates xy2ll(const QPointF &p)
|
||||
{return _projection->xy2ll(_inverted.map(p));}
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect);
|
||||
|
@ -232,13 +232,13 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect)
|
||||
}
|
||||
}
|
||||
|
||||
QPointF OnlineMap::ll2xy(const Coordinates &c) const
|
||||
QPointF OnlineMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
QPointF m = Mercator().ll2xy(c);
|
||||
return QPointF(m.x() / _scale, m.y() / -_scale);
|
||||
}
|
||||
|
||||
Coordinates OnlineMap::xy2ll(const QPointF &p) const
|
||||
Coordinates OnlineMap::xy2ll(const QPointF &p)
|
||||
{
|
||||
QPointF m(p.x() * _scale, -p.y() * _scale);
|
||||
return Mercator().xy2ll(m);
|
||||
|
@ -23,8 +23,8 @@ public:
|
||||
qreal zoomIn();
|
||||
qreal zoomOut();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c) const;
|
||||
Coordinates xy2ll(const QPointF &p) const;
|
||||
QPointF ll2xy(const Coordinates &c);
|
||||
Coordinates xy2ll(const QPointF &p);
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user