mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Now using a strict horizontal map scale
Code cleanup
This commit is contained in:
parent
201256d882
commit
a432ff3461
@ -228,7 +228,8 @@ SOURCES += src/main.cpp \
|
||||
src/map/geocentric.cpp \
|
||||
src/map/mercator.cpp \
|
||||
src/map/jnxmap.cpp \
|
||||
src/map/krovak.cpp
|
||||
src/map/krovak.cpp \
|
||||
src/map/map.cpp
|
||||
RESOURCES += gpxsee.qrc
|
||||
TRANSLATIONS = lang/gpxsee_cs.ts \
|
||||
lang/gpxsee_sv.ts \
|
||||
|
@ -12,7 +12,7 @@
|
||||
#define TL(m) ((m)->xy2pp((m)->bounds().topLeft()))
|
||||
#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;
|
||||
|
||||
@ -161,20 +161,6 @@ QRectF Atlas::bounds() const
|
||||
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)
|
||||
{
|
||||
_zoom = 0;
|
||||
|
@ -16,7 +16,6 @@ public:
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QRectF &rect) const;
|
||||
|
||||
int zoom() const {return _zoom;}
|
||||
void setZoom(int zoom);
|
||||
|
@ -65,7 +65,7 @@ int EmptyMap::zoomFit(const QSize &size, const RectC &rect)
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal EmptyMap::resolution(const QRectF &rect) const
|
||||
qreal EmptyMap::resolution(const QRectF &rect)
|
||||
{
|
||||
qreal scale = zoom2scale(_zoom);
|
||||
|
||||
|
@ -13,7 +13,7 @@ public:
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QRectF &rect) const;
|
||||
qreal resolution(const QRectF &rect);
|
||||
|
||||
int zoom() const {return _zoom;}
|
||||
void setZoom(int zoom) {_zoom = zoom;}
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include <QPainter>
|
||||
#include <QFileInfo>
|
||||
#include <QPixmapCache>
|
||||
#include "transform.h"
|
||||
#include "rectd.h"
|
||||
#include "jnxmap.h"
|
||||
|
||||
@ -146,13 +145,13 @@ JNXMap::JNXMap(const QString &fileName, QObject *parent)
|
||||
_valid = true;
|
||||
}
|
||||
|
||||
QPointF JNXMap::ll2xy(const Coordinates &c) const
|
||||
QPointF JNXMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
const Transform &t = _zooms.at(_zoom).transform;
|
||||
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;
|
||||
PointD pp(t.img2proj(p));
|
||||
@ -168,17 +167,6 @@ QRectF JNXMap::bounds() const
|
||||
_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)
|
||||
{
|
||||
if (!rect.isValid())
|
||||
|
@ -19,7 +19,6 @@ public:
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QRectF &rect) const;
|
||||
|
||||
int zoom() const {return _zoom;}
|
||||
void setZoom(int zoom) {_zoom = zoom;}
|
||||
@ -27,10 +26,8 @@ public:
|
||||
int zoomIn();
|
||||
int zoomOut();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c)
|
||||
{return static_cast<const JNXMap &>(*this).ll2xy(c);}
|
||||
Coordinates xy2ll(const QPointF &p)
|
||||
{return static_cast<const JNXMap &>(*this).xy2ll(p);}
|
||||
QPointF ll2xy(const Coordinates &c);
|
||||
Coordinates xy2ll(const QPointF &p);
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect, bool block);
|
||||
|
||||
@ -50,9 +47,6 @@ private:
|
||||
RTree<Tile*, qreal, 2> tree;
|
||||
};
|
||||
|
||||
QPointF ll2xy(const Coordinates &c) const;
|
||||
Coordinates xy2ll(const QPointF &p) const;
|
||||
|
||||
template<class T> bool readValue(T &val);
|
||||
bool readString(QByteArray &ba);
|
||||
bool readTiles();
|
||||
|
14
src/map/map.cpp
Normal file
14
src/map/map.cpp
Normal 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;
|
||||
}
|
@ -21,7 +21,7 @@ public:
|
||||
virtual const QString &name() 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 void setZoom(int zoom) = 0;
|
||||
|
@ -319,13 +319,13 @@ void OfflineMap::draw(QPainter *painter, const QRectF &rect, bool block)
|
||||
drawImage(painter, rect);
|
||||
}
|
||||
|
||||
QPointF OfflineMap::ll2xy(const Coordinates &c) const
|
||||
QPointF OfflineMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
QPointF p(_transform.proj2img(_projection.ll2xy(c)));
|
||||
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
|
||||
? _projection.xy2ll(_transform.img2proj(QPointF(p.x() / _scale.x(),
|
||||
@ -340,17 +340,6 @@ QRectF OfflineMap::bounds() const
|
||||
: 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)
|
||||
{
|
||||
if (!_ozf)
|
||||
|
@ -21,7 +21,6 @@ public:
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QRectF &rect) const;
|
||||
|
||||
int zoom() const {return _zoom;}
|
||||
void setZoom(int zoom) {_zoom = zoom;}
|
||||
@ -29,10 +28,8 @@ public:
|
||||
int zoomIn();
|
||||
int zoomOut();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c)
|
||||
{return static_cast<const OfflineMap &>(*this).ll2xy(c);}
|
||||
Coordinates xy2ll(const QPointF &p)
|
||||
{return static_cast<const OfflineMap &>(*this).xy2ll(p);}
|
||||
QPointF ll2xy(const Coordinates &c);
|
||||
Coordinates xy2ll(const QPointF &p);
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect, bool block);
|
||||
|
||||
@ -57,9 +54,6 @@ private:
|
||||
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 setImageInfo(const QString &path);
|
||||
|
||||
|
@ -92,7 +92,7 @@ int OnlineMap::zoomFit(const QSize &size, const RectC &rect)
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
qreal OnlineMap::resolution(const QRectF &rect) const
|
||||
qreal OnlineMap::resolution(const QRectF &rect)
|
||||
{
|
||||
qreal scale = zoom2scale(_zoom);
|
||||
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QRectF &rect) const;
|
||||
qreal resolution(const QRectF &rect);
|
||||
|
||||
int zoom() const {return _zoom;}
|
||||
void setZoom(int zoom) {_zoom = zoom;}
|
||||
|
@ -132,17 +132,6 @@ QRectF WMSMap::bounds() const
|
||||
_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)
|
||||
{
|
||||
if (rect.isValid()) {
|
||||
@ -187,12 +176,12 @@ int WMSMap::zoomOut()
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
QPointF WMSMap::ll2xy(const Coordinates &c) const
|
||||
QPointF WMSMap::ll2xy(const Coordinates &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));
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ public:
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QRectF &rect) const;
|
||||
|
||||
int zoom() const {return _zoom;}
|
||||
void setZoom(int zoom);
|
||||
@ -27,10 +26,8 @@ public:
|
||||
int zoomIn();
|
||||
int zoomOut();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c)
|
||||
{return static_cast<const WMSMap &>(*this).ll2xy(c);}
|
||||
Coordinates xy2ll(const QPointF &p)
|
||||
{return static_cast<const WMSMap &>(*this).xy2ll(p);}
|
||||
QPointF ll2xy(const Coordinates &c);
|
||||
Coordinates xy2ll(const QPointF &p);
|
||||
|
||||
void draw(QPainter *painter, const QRectF &rect, bool block);
|
||||
|
||||
@ -47,9 +44,6 @@ private:
|
||||
void updateTransform();
|
||||
bool loadWMS();
|
||||
|
||||
QPointF ll2xy(const Coordinates &c) const;
|
||||
Coordinates xy2ll(const QPointF &p) const;
|
||||
|
||||
QString _name;
|
||||
|
||||
WMS::Setup _setup;
|
||||
|
@ -132,17 +132,6 @@ int WMTSMap::zoomFit(const QSize &size, const RectC &rect)
|
||||
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)
|
||||
{
|
||||
_zoom = zoom;
|
||||
|
@ -18,7 +18,6 @@ public:
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
QRectF bounds() const;
|
||||
qreal resolution(const QRectF &rect) const;
|
||||
|
||||
int zoom() const {return _zoom;}
|
||||
void setZoom(int zoom);
|
||||
|
Loading…
Reference in New Issue
Block a user