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

Fixed broken atlas maps fitting in non-orthogonal projections.

This commit is contained in:
Martin Tůma 2017-03-31 19:18:01 +02:00
parent 3763d44662
commit b1748c848b
3 changed files with 30 additions and 19 deletions

View File

@ -7,8 +7,8 @@
#define ZOOM_THRESHOLD 0.9 #define ZOOM_THRESHOLD 0.9
#define TL(m) ((m)->xy2ll((m)->bounds().topLeft())) #define TL(m) ((m)->xy2pp((m)->bounds().topLeft()))
#define BR(m) ((m)->xy2ll((m)->bounds().bottomRight())) #define BR(m) ((m)->xy2pp((m)->bounds().bottomRight()))
static bool resCmp(const OfflineMap *m1, const OfflineMap *m2) static bool resCmp(const OfflineMap *m1, const OfflineMap *m2)
{ {
@ -22,12 +22,12 @@ static bool resCmp(const OfflineMap *m1, const OfflineMap *m2)
static bool lonCmp(const OfflineMap *m1, const OfflineMap *m2) static bool lonCmp(const OfflineMap *m1, const OfflineMap *m2)
{ {
return TL(m1).lon() < TL(m2).lon(); return TL(m1).x() < TL(m2).x();
} }
static bool latCmp(const OfflineMap *m1, const OfflineMap *m2) static bool latCmp(const OfflineMap *m1, const OfflineMap *m2)
{ {
return TL(m1).lat() > TL(m2).lat(); return TL(m1).y() > TL(m2).y();
} }
bool Atlas::isAtlas(const QFileInfoList &files) bool Atlas::isAtlas(const QFileInfoList &files)
@ -83,28 +83,25 @@ void Atlas::computeBounds()
qSort(m.begin(), m.end(), lonCmp); qSort(m.begin(), m.end(), lonCmp);
offsets[_maps.indexOf(m.first())].setX(w); offsets[_maps.indexOf(m.first())].setX(w);
for (int i = 1; i < m.size(); i++) { for (int i = 1; i < m.size(); i++) {
if (TL(m.at(i)).lon() > TL(m.at(i-1)).lon()) { if (TL(m.at(i)).x() > TL(m.at(i-1)).x()) {
w += m.at(i-1)->ll2xy(Coordinates(TL(m.at(i)).lon(), w += round(m.at(i-1)->pp2xy(TL(m.at(i))).x());
TL(m.at(i-1)).lat())).x() - m.at(i-1)->bounds().left(); offsets[_maps.indexOf(m.at(i))].setX(w);
offsets[_maps.indexOf(m.at(i))].setX(round(w));
} }
} }
qSort(m.begin(), m.end(), latCmp); qSort(m.begin(), m.end(), latCmp);
offsets[_maps.indexOf(m.first())].setY(h); offsets[_maps.indexOf(m.first())].setY(h);
for (int i = 1; i < m.size(); i++) { for (int i = 1; i < m.size(); i++) {
if (TL(m.at(i)).lat() < TL(m.at(i-1)).lat()) { if (TL(m.at(i)).y() < TL(m.at(i-1)).y()) {
h += m.at(i-1)->ll2xy(Coordinates(TL(m.at(i-1)).lon(), h += round(m.at(i-1)->pp2xy(TL(m.at(i))).y());
TL(m.at(i)).lat())).y() - m.at(i-1)->bounds().top(); offsets[_maps.indexOf(m.at(i))].setY(h);
offsets[_maps.indexOf(m.at(i))].setY(round(h));
} }
} }
} }
for (int i = 0; i < _maps.count(); i++) for (int i = 0; i < _maps.count(); i++)
_bounds.append(QPair<QRectF, QRectF>(QRectF(TL(_maps.at(i)).toPointF(), _bounds.append(QPair<QRectF, QRectF>(QRectF(TL(_maps.at(i)),
BR(_maps.at(i)).toPointF()), QRectF(offsets.at(i), BR(_maps.at(i))), QRectF(offsets.at(i), _maps.at(i)->bounds().size())));
_maps.at(i)->bounds().size())));
} }
Atlas::Atlas(const QString &path, QObject *parent) : Map(parent) Atlas::Atlas(const QString &path, QObject *parent) : Map(parent)
@ -165,7 +162,7 @@ qreal Atlas::resolution(const QPointF &p) const
int idx = _zooms.at(_zoom).first; int idx = _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++) {
if (_bounds.at(i).second.contains(p)) { if (_bounds.at(i).second.contains(_maps.at(i)->xy2pp(p))) {
idx = i; idx = i;
break; break;
} }
@ -185,7 +182,8 @@ qreal Atlas::zoomFit(const QSize &size, const QRectF &br)
for (int z = 0; z < _zooms.count(); z++) { for (int z = 0; z < _zooms.count(); z++) {
for (int i = _zooms.at(z).first; i <= _zooms.at(z).second; i++) { for (int i = _zooms.at(z).first; i <= _zooms.at(z).second; i++) {
if (_bounds.at(i).first.contains(br.center())) if (_bounds.at(i).first.contains(_maps.at(i)->xy2pp(
_maps.at(i)->ll2xy(br.center()))))
continue; continue;
QRect sbr = QRectF(_maps.at(i)->ll2xy(br.topLeft()), QRect sbr = QRectF(_maps.at(i)->ll2xy(br.topLeft()),
@ -220,7 +218,8 @@ QPointF Atlas::ll2xy(const Coordinates &c) const
int idx = _zooms.at(_zoom).first; int idx = _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++) {
if (_bounds.at(i).first.contains(c.lon(), c.lat())) { if (_bounds.at(i).first.contains(_maps.at(i)->xy2pp(
_maps.at(i)->ll2xy(c)))) {
idx = i; idx = i;
break; break;
} }
@ -235,7 +234,7 @@ Coordinates Atlas::xy2ll(const QPointF &p) const
int idx = _zooms.at(_zoom).first; int idx = _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++) {
if (_bounds.at(i).second.contains(p)) { if (_bounds.at(i).second.contains(_maps.at(i)->xy2pp(p))) {
idx = i; idx = i;
break; break;
} }

View File

@ -514,3 +514,13 @@ Coordinates OfflineMap::xy2ll(const QPointF &p) const
{ {
return _projection->xy2ll(_transform.inverted().map(p)); return _projection->xy2ll(_transform.inverted().map(p));
} }
QPointF OfflineMap::xy2pp(const QPointF &p) const
{
return _transform.inverted().map(p);
}
QPointF OfflineMap::pp2xy(const QPointF &p) const
{
return _transform.map(p);
}

View File

@ -38,6 +38,8 @@ public:
void unload(); void unload();
bool isValid() {return _valid;} bool isValid() {return _valid;}
QPointF xy2pp(const QPointF &p) const;
QPointF pp2xy(const QPointF &p) const;
private: private:
typedef QPair<QPoint, Coordinates> ReferencePoint; typedef QPair<QPoint, Coordinates> ReferencePoint;