1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-25 18:49:16 +02:00

RectC now uses the expected axis direction

+ some more refactoring
This commit is contained in:
2018-04-16 20:26:10 +02:00
parent b26a10a5b3
commit 9e36451001
19 changed files with 90 additions and 115 deletions

View File

@ -2,7 +2,7 @@
#define CT_H
#include "common/coordinates.h"
#include "point.h"
#include "pointd.h"
class CT {
public:

View File

@ -51,15 +51,15 @@ QRectF EmptyMap::bounds() const
return QRectF(ll2xy(Coordinates(-180, 85)), ll2xy(Coordinates(180, -85)));
}
int EmptyMap::zoomFit(const QSize &size, const RectC &br)
int EmptyMap::zoomFit(const QSize &size, const RectC &rect)
{
if (!br.isValid())
if (!rect.isValid())
_zoom = ZOOM_MAX;
else {
QRectF tbr(ll2m(br.topLeft()), ll2m(br.bottomRight()));
QRectF tbr(ll2m(rect.topLeft()), ll2m(rect.bottomRight()));
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
_zoom = limitZoom(scale2zoom(qMax(sc.x(), sc.y())));
_zoom = limitZoom(scale2zoom(qMax(sc.x(), -sc.y())));
}
return _zoom;

View File

@ -16,7 +16,7 @@ public:
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;}
int zoomFit(const QSize &size, const RectC &br);
int zoomFit(const QSize &size, const RectC &rect);
int zoomIn();
int zoomOut();

View File

@ -3,7 +3,7 @@
#include <cmath>
#include <QDebug>
#include "point.h"
#include "pointd.h"
class LinearUnits
{

View File

@ -24,7 +24,7 @@ public:
virtual qreal resolution(const QRectF &rect) const = 0;
virtual int zoom() const = 0;
virtual int zoomFit(const QSize &size, const RectC &br) = 0;
virtual int zoomFit(const QSize &size, const RectC &rect) = 0;
virtual int zoomIn() = 0;
virtual int zoomOut() = 0;

View File

@ -42,8 +42,8 @@ static int scale2zoom(qreal scale)
OnlineMap::OnlineMap(const QString &name, const QString &url,
const Range &zooms, const RectC &bounds, QObject *parent) :
Map(parent), _name(name), _zooms(zooms), _bounds(bounds),
_block(false), _valid(false)
Map(parent), _name(name), _zooms(zooms), _bounds(bounds), _block(false),
_valid(false)
{
QString dir(TILES_DIR + "/" + _name);
@ -90,15 +90,14 @@ int OnlineMap::limitZoom(int zoom) const
return zoom;
}
int OnlineMap::zoomFit(const QSize &size, const RectC &br)
int OnlineMap::zoomFit(const QSize &size, const RectC &rect)
{
if (!br.isValid())
if (!rect.isValid())
_zoom = _zooms.max();
else {
QRectF tbr(ll2m(br.topLeft()), ll2m(br.bottomRight()));
QRectF tbr(ll2m(rect.topLeft()), ll2m(rect.bottomRight()));
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
_zoom = limitZoom(scale2zoom(qMax(sc.x(), sc.y())));
_zoom = limitZoom(scale2zoom(qMax(sc.x(), -sc.y())));
}
return _zoom;

View File

@ -20,7 +20,7 @@ public:
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;}
int zoomFit(const QSize &size, const RectC &br);
int zoomFit(const QSize &size, const RectC &rect);
int zoomIn();
int zoomOut();

View File

@ -5,7 +5,8 @@
#include <QPointF>
#include <QDebug>
class PointD {
class PointD
{
public:
PointD() : _x(NAN), _y(NAN) {}
PointD(double x, double y) : _x(x), _y(y) {}

View File

@ -3,7 +3,7 @@
#include <QDebug>
#include "common/coordinates.h"
#include "point.h"
#include "pointd.h"
#include "linearunits.h"
#include "coordinatesystem.h"

View File

@ -4,7 +4,7 @@
#include <QTransform>
#include <QList>
#include <QDebug>
#include "point.h"
#include "pointd.h"
class ReferencePoint
{

View File

@ -60,15 +60,17 @@ void WMSMap::computeZooms(const RangeF &scaleDenominator)
void WMSMap::updateTransform()
{
double scaleDenominator = _zooms.at(_zoom);
double pixelSpan = sd2res(scaleDenominator);
double pixelSpan = sd2res(_zooms.at(_zoom));
if (_projection.isGeographic())
pixelSpan /= deg2rad(WGS84_RADIUS);
double sx = (_br.x() - _tl.x()) / pixelSpan;
double sy = (_tl.y() - _br.y()) / pixelSpan;
ReferencePoint tl(PointD(0, 0), _boundingBox.topLeft());
ReferencePoint br(PointD(_boundingBox.width() / pixelSpan,
-_boundingBox.height() / pixelSpan), _boundingBox.bottomRight());
ReferencePoint tl(PointD(0, 0), _tl);
ReferencePoint br(PointD(sx, sy), _br);
_transform = Transform(tl, br);
_bounds = QRectF(QPointF(0, 0), QSizeF(sx, sy));
}
bool WMSMap::loadWMS()
@ -82,10 +84,8 @@ bool WMSMap::loadWMS()
}
_projection = wms.projection();
RectC bb = wms.boundingBox().normalized();
_boundingBox = QRectF(_projection.ll2xy(Coordinates(bb.topLeft().lon(),
bb.bottomRight().lat())).toPointF(), _projection.ll2xy(Coordinates(
bb.bottomRight().lon(), bb.topLeft().lat())).toPointF());
_tl = _projection.ll2xy(wms.boundingBox().topLeft());
_br = _projection.ll2xy(wms.boundingBox().bottomRight());
_tileLoader = TileLoader(tileUrl(wms.version()), tilesDir(),
_setup.authorization());
@ -141,17 +141,6 @@ void WMSMap::emitLoaded()
emit loaded();
}
QRectF WMSMap::bounds() const
{
double pixelSpan = sd2res(_zooms.at(_zoom));
if (_projection.isGeographic())
pixelSpan /= deg2rad(WGS84_RADIUS);
QSizeF size(_boundingBox.width() / pixelSpan, -_boundingBox.height()
/ pixelSpan);
return QRectF(QPointF(0, 0), size);
}
qreal WMSMap::resolution(const QRectF &rect) const
{
Coordinates tl = xy2ll((rect.topLeft()));
@ -163,12 +152,13 @@ qreal WMSMap::resolution(const QRectF &rect) const
return ds/ps;
}
int WMSMap::zoomFit(const QSize &size, const RectC &br)
int WMSMap::zoomFit(const QSize &size, const RectC &rect)
{
if (br.isValid()) {
QRectF tbr(_projection.ll2xy(br.topLeft()).toPointF(),
_projection.ll2xy(br.bottomRight()).toPointF());
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
if (rect.isValid()) {
PointD tl(_projection.ll2xy(rect.topLeft()));
PointD br(_projection.ll2xy(rect.bottomRight()));
PointD sc((br.x() - tl.x()) / size.width(), (tl.y() - br.y())
/ size.height());
double resolution = qMax(qAbs(sc.x()), qAbs(sc.y()));
if (_projection.isGeographic())
resolution *= deg2rad(WGS84_RADIUS);

View File

@ -17,11 +17,11 @@ public:
const QString &name() const {return _name;}
QRectF bounds() const;
QRectF bounds() const {return _bounds;}
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;}
int zoomFit(const QSize &size, const RectC &br);
int zoomFit(const QSize &size, const RectC &rect);
int zoomIn();
int zoomOut();
@ -63,7 +63,8 @@ private:
Transform _transform;
CoordinateSystem _cs;
QVector<double> _zooms;
QRectF _boundingBox;
PointD _tl, _br;
QRectF _bounds;
int _zoom;
bool _block;

View File

@ -122,13 +122,14 @@ QRectF WMTSMap::bounds() const
return _bounds.isValid() ? tileBounds.intersected(bounds) : tileBounds;
}
int WMTSMap::zoomFit(const QSize &size, const RectC &br)
int WMTSMap::zoomFit(const QSize &size, const RectC &rect)
{
if (br.isValid()) {
QRectF tbr(_projection.ll2xy(br.topLeft()).toPointF(),
_projection.ll2xy(br.bottomRight()).toPointF());
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
qreal resolution = qMax(qAbs(sc.x()), qAbs(sc.y()));
if (rect.isValid()) {
PointD tl(_projection.ll2xy(rect.topLeft()));
PointD br(_projection.ll2xy(rect.bottomRight()));
PointD sc((br.x() - tl.x()) / size.width(), (tl.y() - br.y())
/ size.height());
double resolution = qMax(qAbs(sc.x()), qAbs(sc.y()));
if (_projection.isGeographic())
resolution *= deg2rad(WGS84_RADIUS);

View File

@ -21,7 +21,7 @@ public:
qreal resolution(const QRectF &rect) const;
int zoom() const {return _zoom;}
int zoomFit(const QSize &size, const RectC &br);
int zoomFit(const QSize &size, const RectC &rect);
int zoomIn();
int zoomOut();