1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 06:43:22 +02:00

Now using a strict horizontal map scale

Code cleanup
This commit is contained in:
Martin Tůma 2018-06-30 12:14:58 +02:00
parent 201256d882
commit a432ff3461
17 changed files with 34 additions and 98 deletions

View File

@ -228,7 +228,8 @@ SOURCES += src/main.cpp \
src/map/geocentric.cpp \ src/map/geocentric.cpp \
src/map/mercator.cpp \ src/map/mercator.cpp \
src/map/jnxmap.cpp \ src/map/jnxmap.cpp \
src/map/krovak.cpp src/map/krovak.cpp \
src/map/map.cpp
RESOURCES += gpxsee.qrc RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts \ TRANSLATIONS = lang/gpxsee_cs.ts \
lang/gpxsee_sv.ts \ lang/gpxsee_sv.ts \

View File

@ -12,7 +12,7 @@
#define TL(m) ((m)->xy2pp((m)->bounds().topLeft())) #define TL(m) ((m)->xy2pp((m)->bounds().topLeft()))
#define BR(m) ((m)->xy2pp((m)->bounds().bottomRight())) #define BR(m) ((m)->xy2pp((m)->bounds().bottomRight()))
static bool resCmp(const OfflineMap *m1, const OfflineMap *m2) static bool resCmp(OfflineMap *m1, OfflineMap *m2)
{ {
qreal r1, r2; qreal r1, r2;
@ -161,20 +161,6 @@ QRectF Atlas::bounds() const
return QRectF(QPointF(0, 0), s); return QRectF(QPointF(0, 0), s);
} }
qreal Atlas::resolution(const QRectF &rect) const
{
int idx = _zooms.at(_zoom).first;
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).last; i++) {
if (_bounds.at(i).xy.contains(rect.center())) {
idx = i;
break;
}
}
return _maps.at(idx)->resolution(rect);
}
int Atlas::zoomFit(const QSize &size, const RectC &br) int Atlas::zoomFit(const QSize &size, const RectC &br)
{ {
_zoom = 0; _zoom = 0;

View File

@ -16,7 +16,6 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
QRectF bounds() const; QRectF bounds() const;
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;} int zoom() const {return _zoom;}
void setZoom(int zoom); void setZoom(int zoom);

View File

@ -65,7 +65,7 @@ int EmptyMap::zoomFit(const QSize &size, const RectC &rect)
return _zoom; return _zoom;
} }
qreal EmptyMap::resolution(const QRectF &rect) const qreal EmptyMap::resolution(const QRectF &rect)
{ {
qreal scale = zoom2scale(_zoom); qreal scale = zoom2scale(_zoom);

View File

@ -13,7 +13,7 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
QRectF bounds() const; QRectF bounds() const;
qreal resolution(const QRectF &rect) const; qreal resolution(const QRectF &rect);
int zoom() const {return _zoom;} int zoom() const {return _zoom;}
void setZoom(int zoom) {_zoom = zoom;} void setZoom(int zoom) {_zoom = zoom;}

View File

@ -2,7 +2,6 @@
#include <QPainter> #include <QPainter>
#include <QFileInfo> #include <QFileInfo>
#include <QPixmapCache> #include <QPixmapCache>
#include "transform.h"
#include "rectd.h" #include "rectd.h"
#include "jnxmap.h" #include "jnxmap.h"
@ -146,13 +145,13 @@ JNXMap::JNXMap(const QString &fileName, QObject *parent)
_valid = true; _valid = true;
} }
QPointF JNXMap::ll2xy(const Coordinates &c) const QPointF JNXMap::ll2xy(const Coordinates &c)
{ {
const Transform &t = _zooms.at(_zoom).transform; const Transform &t = _zooms.at(_zoom).transform;
return t.proj2img(PointD(c.lon(), c.lat())); return t.proj2img(PointD(c.lon(), c.lat()));
} }
Coordinates JNXMap::xy2ll(const QPointF &p) const Coordinates JNXMap::xy2ll(const QPointF &p)
{ {
const Transform &t = _zooms.at(_zoom).transform; const Transform &t = _zooms.at(_zoom).transform;
PointD pp(t.img2proj(p)); PointD pp(t.img2proj(p));
@ -168,17 +167,6 @@ QRectF JNXMap::bounds() const
_bounds.bottomRight().lat()))); _bounds.bottomRight().lat())));
} }
qreal JNXMap::resolution(const QRectF &rect) const
{
Coordinates tl = xy2ll((rect.topLeft()));
Coordinates br = xy2ll(rect.bottomRight());
qreal ds = tl.distanceTo(br);
qreal ps = QLineF(rect.topLeft(), rect.bottomRight()).length();
return ds/ps;
}
int JNXMap::zoomFit(const QSize &size, const RectC &rect) int JNXMap::zoomFit(const QSize &size, const RectC &rect)
{ {
if (!rect.isValid()) if (!rect.isValid())

View File

@ -19,7 +19,6 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
QRectF bounds() const; QRectF bounds() const;
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;} int zoom() const {return _zoom;}
void setZoom(int zoom) {_zoom = zoom;} void setZoom(int zoom) {_zoom = zoom;}
@ -27,10 +26,8 @@ public:
int zoomIn(); int zoomIn();
int zoomOut(); int zoomOut();
QPointF ll2xy(const Coordinates &c) QPointF ll2xy(const Coordinates &c);
{return static_cast<const JNXMap &>(*this).ll2xy(c);} Coordinates xy2ll(const QPointF &p);
Coordinates xy2ll(const QPointF &p)
{return static_cast<const JNXMap &>(*this).xy2ll(p);}
void draw(QPainter *painter, const QRectF &rect, bool block); void draw(QPainter *painter, const QRectF &rect, bool block);
@ -50,9 +47,6 @@ private:
RTree<Tile*, qreal, 2> tree; RTree<Tile*, qreal, 2> tree;
}; };
QPointF ll2xy(const Coordinates &c) const;
Coordinates xy2ll(const QPointF &p) const;
template<class T> bool readValue(T &val); template<class T> bool readValue(T &val);
bool readString(QByteArray &ba); bool readString(QByteArray &ba);
bool readTiles(); bool readTiles();

14
src/map/map.cpp Normal file
View File

@ -0,0 +1,14 @@
#include <QLineF>
#include "map.h"
qreal Map::resolution(const QRectF &rect)
{
qreal cy = rect.center().y();
QPointF cl(rect.left(), cy);
QPointF cr(rect.right(), cy);
qreal ds = xy2ll(cl).distanceTo(xy2ll(cr));
qreal ps = QLineF(cl, cr).length();
return ds/ps;
}

View File

@ -21,7 +21,7 @@ public:
virtual const QString &name() const = 0; virtual const QString &name() const = 0;
virtual QRectF bounds() const = 0; virtual QRectF bounds() const = 0;
virtual qreal resolution(const QRectF &rect) const = 0; virtual qreal resolution(const QRectF &rect);
virtual int zoom() const = 0; virtual int zoom() const = 0;
virtual void setZoom(int zoom) = 0; virtual void setZoom(int zoom) = 0;

View File

@ -319,13 +319,13 @@ void OfflineMap::draw(QPainter *painter, const QRectF &rect, bool block)
drawImage(painter, rect); drawImage(painter, rect);
} }
QPointF OfflineMap::ll2xy(const Coordinates &c) const QPointF OfflineMap::ll2xy(const Coordinates &c)
{ {
QPointF p(_transform.proj2img(_projection.ll2xy(c))); QPointF p(_transform.proj2img(_projection.ll2xy(c)));
return _ozf ? QPointF(p.x() * _scale.x(), p.y() * _scale.y()) : p; return _ozf ? QPointF(p.x() * _scale.x(), p.y() * _scale.y()) : p;
} }
Coordinates OfflineMap::xy2ll(const QPointF &p) const Coordinates OfflineMap::xy2ll(const QPointF &p)
{ {
return _ozf return _ozf
? _projection.xy2ll(_transform.img2proj(QPointF(p.x() / _scale.x(), ? _projection.xy2ll(_transform.img2proj(QPointF(p.x() / _scale.x(),
@ -340,17 +340,6 @@ QRectF OfflineMap::bounds() const
: QRectF(QPointF(0, 0), _map.size); : QRectF(QPointF(0, 0), _map.size);
} }
qreal OfflineMap::resolution(const QRectF &rect) const
{
Coordinates tl = xy2ll((rect.topLeft()));
Coordinates br = xy2ll(rect.bottomRight());
qreal ds = tl.distanceTo(br);
qreal ps = QLineF(rect.topLeft(), rect.bottomRight()).length();
return ds/ps;
}
int OfflineMap::zoomFit(const QSize &size, const RectC &rect) int OfflineMap::zoomFit(const QSize &size, const RectC &rect)
{ {
if (!_ozf) if (!_ozf)

View File

@ -21,7 +21,6 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
QRectF bounds() const; QRectF bounds() const;
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;} int zoom() const {return _zoom;}
void setZoom(int zoom) {_zoom = zoom;} void setZoom(int zoom) {_zoom = zoom;}
@ -29,10 +28,8 @@ public:
int zoomIn(); int zoomIn();
int zoomOut(); int zoomOut();
QPointF ll2xy(const Coordinates &c) QPointF ll2xy(const Coordinates &c);
{return static_cast<const OfflineMap &>(*this).ll2xy(c);} Coordinates xy2ll(const QPointF &p);
Coordinates xy2ll(const QPointF &p)
{return static_cast<const OfflineMap &>(*this).xy2ll(p);}
void draw(QPainter *painter, const QRectF &rect, bool block); void draw(QPainter *painter, const QRectF &rect, bool block);
@ -57,9 +54,6 @@ private:
bool isValid() const {return size.isValid() && !path.isEmpty();} bool isValid() const {return size.isValid() && !path.isEmpty();}
}; };
QPointF ll2xy(const Coordinates &c) const;
Coordinates xy2ll(const QPointF &p) const;
bool setTileInfo(const QStringList &tiles, const QString &path = QString()); bool setTileInfo(const QStringList &tiles, const QString &path = QString());
bool setImageInfo(const QString &path); bool setImageInfo(const QString &path);

View File

@ -92,7 +92,7 @@ int OnlineMap::zoomFit(const QSize &size, const RectC &rect)
return _zoom; return _zoom;
} }
qreal OnlineMap::resolution(const QRectF &rect) const qreal OnlineMap::resolution(const QRectF &rect)
{ {
qreal scale = zoom2scale(_zoom); qreal scale = zoom2scale(_zoom);

View File

@ -18,7 +18,7 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
QRectF bounds() const; QRectF bounds() const;
qreal resolution(const QRectF &rect) const; qreal resolution(const QRectF &rect);
int zoom() const {return _zoom;} int zoom() const {return _zoom;}
void setZoom(int zoom) {_zoom = zoom;} void setZoom(int zoom) {_zoom = zoom;}

View File

@ -132,17 +132,6 @@ QRectF WMSMap::bounds() const
_transform.proj2img(_bbox.bottomRight())); _transform.proj2img(_bbox.bottomRight()));
} }
qreal WMSMap::resolution(const QRectF &rect) const
{
Coordinates tl = xy2ll((rect.topLeft()));
Coordinates br = xy2ll(rect.bottomRight());
qreal ds = tl.distanceTo(br);
qreal ps = QLineF(rect.topLeft(), rect.bottomRight()).length();
return ds/ps;
}
int WMSMap::zoomFit(const QSize &size, const RectC &rect) int WMSMap::zoomFit(const QSize &size, const RectC &rect)
{ {
if (rect.isValid()) { if (rect.isValid()) {
@ -187,12 +176,12 @@ int WMSMap::zoomOut()
return _zoom; return _zoom;
} }
QPointF WMSMap::ll2xy(const Coordinates &c) const QPointF WMSMap::ll2xy(const Coordinates &c)
{ {
return _transform.proj2img(_projection.ll2xy(c)); return _transform.proj2img(_projection.ll2xy(c));
} }
Coordinates WMSMap::xy2ll(const QPointF &p) const Coordinates WMSMap::xy2ll(const QPointF &p)
{ {
return _projection.xy2ll(_transform.img2proj(p)); return _projection.xy2ll(_transform.img2proj(p));
} }

View File

@ -19,7 +19,6 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
QRectF bounds() const; QRectF bounds() const;
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;} int zoom() const {return _zoom;}
void setZoom(int zoom); void setZoom(int zoom);
@ -27,10 +26,8 @@ public:
int zoomIn(); int zoomIn();
int zoomOut(); int zoomOut();
QPointF ll2xy(const Coordinates &c) QPointF ll2xy(const Coordinates &c);
{return static_cast<const WMSMap &>(*this).ll2xy(c);} Coordinates xy2ll(const QPointF &p);
Coordinates xy2ll(const QPointF &p)
{return static_cast<const WMSMap &>(*this).xy2ll(p);}
void draw(QPainter *painter, const QRectF &rect, bool block); void draw(QPainter *painter, const QRectF &rect, bool block);
@ -47,9 +44,6 @@ private:
void updateTransform(); void updateTransform();
bool loadWMS(); bool loadWMS();
QPointF ll2xy(const Coordinates &c) const;
Coordinates xy2ll(const QPointF &p) const;
QString _name; QString _name;
WMS::Setup _setup; WMS::Setup _setup;

View File

@ -132,17 +132,6 @@ int WMTSMap::zoomFit(const QSize &size, const RectC &rect)
return _zoom; return _zoom;
} }
qreal WMTSMap::resolution(const QRectF &rect) const
{
Coordinates tl = xy2ll((rect.topLeft()));
Coordinates br = xy2ll(rect.bottomRight());
qreal ds = tl.distanceTo(br);
qreal ps = QLineF(rect.topLeft(), rect.bottomRight()).length();
return ds/ps;
}
void WMTSMap::setZoom(int zoom) void WMTSMap::setZoom(int zoom)
{ {
_zoom = zoom; _zoom = zoom;

View File

@ -18,7 +18,6 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
QRectF bounds() const; QRectF bounds() const;
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;} int zoom() const {return _zoom;}
void setZoom(int zoom); void setZoom(int zoom);