1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-31 09:05:14 +01:00

Using a more human-readable online maps bounds definition

This commit is contained in:
Martin Tůma 2018-01-26 01:26:26 +01:00
parent 66f0f6a202
commit 04a145a2e7
5 changed files with 22 additions and 18 deletions

View File

@ -18,7 +18,7 @@ EmptyMap::EmptyMap(QObject *parent) : Map(parent)
QRectF EmptyMap::bounds() const
{
return scaled(QRectF(QPointF(-180, -180), QSizeF(360, 360)), 1.0/_scale);
return QRectF(ll2xy(Coordinates(-180, 85)), ll2xy(Coordinates(180, -85)));
}
qreal EmptyMap::zoomFit(const QSize &size, const RectC &br)
@ -72,13 +72,13 @@ void EmptyMap::draw(QPainter *painter, const QRectF &rect)
painter->fillRect(rect, _backgroundColor);
}
QPointF EmptyMap::ll2xy(const Coordinates &c)
QPointF EmptyMap::ll2xy(const Coordinates &c) const
{
QPointF m = Mercator().ll2xy(c);
return QPointF(m.x() / _scale, m.y() / -_scale);
}
Coordinates EmptyMap::xy2ll(const QPointF &p)
Coordinates EmptyMap::xy2ll(const QPointF &p) const
{
QPointF m(p.x() * _scale, -p.y() * _scale);
return Mercator().xy2ll(m);

View File

@ -1,6 +1,7 @@
#ifndef EMPTYMAP_H
#define EMPTYMAP_H
#include "common/coordinates.h"
#include "map.h"
class EmptyMap : public Map
@ -21,12 +22,17 @@ public:
qreal zoomIn();
qreal zoomOut();
QPointF ll2xy(const Coordinates &c);
Coordinates xy2ll(const QPointF &p);
QPointF ll2xy(const Coordinates &c)
{return static_cast<const EmptyMap &>(*this).ll2xy(c);}
Coordinates xy2ll(const QPointF &p)
{return static_cast<const EmptyMap &>(*this).xy2ll(p);}
void draw(QPainter *painter, const QRectF &rect);
private:
QPointF ll2xy(const Coordinates &c) const;
Coordinates xy2ll(const QPointF &p) const;
QString _name;
qreal _scale;
};

View File

@ -1,7 +0,0 @@
#include <QRectF>
inline QRectF scaled(const QRectF &rect, qreal factor)
{
return QRectF(QPointF(rect.left() * factor, rect.top() * factor),
QSizeF(rect.width() * factor, rect.height() * factor));
}

View File

@ -168,8 +168,7 @@ void OnlineMap::clearCache()
QRectF OnlineMap::bounds() const
{
return scaled(QRectF(QPointF(-180, -180), QSizeF(360, 360)),
1.0/zoom2scale(_zoom));
return QRectF(ll2xy(Coordinates(-180, 85)), ll2xy(Coordinates(180, -85)));
}
int OnlineMap::limitZoom(int zoom) const
@ -253,14 +252,14 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect)
}
}
QPointF OnlineMap::ll2xy(const Coordinates &c)
QPointF OnlineMap::ll2xy(const Coordinates &c) const
{
qreal scale = zoom2scale(_zoom);
QPointF m = Mercator().ll2xy(c);
return QPointF(m.x() / scale, m.y() / -scale);
}
Coordinates OnlineMap::xy2ll(const QPointF &p)
Coordinates OnlineMap::xy2ll(const QPointF &p) const
{
qreal scale = zoom2scale(_zoom);
QPointF m(p.x() * scale, -p.y() * scale);

View File

@ -1,6 +1,7 @@
#ifndef ONLINEMAP_H
#define ONLINEMAP_H
#include "common/coordinates.h"
#include "common/range.h"
#include "map.h"
#include "tile.h"
@ -26,8 +27,10 @@ public:
qreal zoomIn();
qreal zoomOut();
QPointF ll2xy(const Coordinates &c);
Coordinates xy2ll(const QPointF &p);
QPointF ll2xy(const Coordinates &c)
{return static_cast<const OnlineMap &>(*this).ll2xy(c);}
Coordinates xy2ll(const QPointF &p)
{return static_cast<const OnlineMap &>(*this).xy2ll(p);}
void draw(QPainter *painter, const QRectF &rect);
@ -44,6 +47,9 @@ private slots:
void emitLoaded();
private:
QPointF ll2xy(const Coordinates &c) const;
Coordinates xy2ll(const QPointF &p) const;
void fillTile(Tile &tile);
QString tileUrl(const Tile &tile) const;
QString tileFile(const Tile &tile) const;