2017-03-18 01:30:31 +01:00
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QPainter>
|
|
|
|
#include "misc.h"
|
|
|
|
#include "rd.h"
|
|
|
|
#include "wgs84.h"
|
|
|
|
#include "coordinates.h"
|
2017-03-29 00:17:47 +02:00
|
|
|
#include "mercator.h"
|
2017-03-18 01:30:31 +01:00
|
|
|
#include "emptymap.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define SCALE_MIN 0.5
|
|
|
|
#define SCALE_MAX 1.0E-6
|
|
|
|
|
|
|
|
EmptyMap::EmptyMap(QObject *parent) : Map(parent)
|
|
|
|
{
|
|
|
|
_scale = SCALE_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF EmptyMap::bounds() const
|
|
|
|
{
|
|
|
|
return scaled(QRectF(QPointF(-180, -180), QSizeF(360, 360)), 1.0/_scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal EmptyMap::zoomFit(const QSize &size, const QRectF &br)
|
|
|
|
{
|
|
|
|
if (br.isNull())
|
|
|
|
_scale = SCALE_MAX;
|
|
|
|
else {
|
|
|
|
Coordinates topLeft(br.topLeft());
|
|
|
|
Coordinates bottomRight(br.bottomRight());
|
2017-03-29 00:17:47 +02:00
|
|
|
QRectF tbr(Mercator().ll2xy(topLeft), Mercator().ll2xy(bottomRight));
|
2017-03-18 01:30:31 +01:00
|
|
|
|
|
|
|
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
|
|
|
|
|
|
|
_scale = qMax(sc.x(), sc.y());
|
|
|
|
}
|
|
|
|
|
|
|
|
_scale = qMax(_scale, SCALE_MAX);
|
|
|
|
_scale = qMin(_scale, SCALE_MIN);
|
|
|
|
|
|
|
|
return _scale;
|
|
|
|
}
|
|
|
|
|
2017-06-26 00:20:42 +02:00
|
|
|
qreal EmptyMap::zoomFit(qreal resolution, const Coordinates &c)
|
|
|
|
{
|
|
|
|
_scale = (360.0 * resolution) / (WGS84_RADIUS * 2 * M_PI
|
|
|
|
* cos(deg2rad(c.lat())));
|
|
|
|
|
|
|
|
_scale = qMax(_scale, SCALE_MAX);
|
|
|
|
_scale = qMin(_scale, SCALE_MIN);
|
|
|
|
|
|
|
|
return _scale;
|
|
|
|
}
|
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
qreal EmptyMap::resolution(const QPointF &p) const
|
|
|
|
{
|
|
|
|
return (WGS84_RADIUS * 2 * M_PI * _scale / 360.0
|
|
|
|
* cos(2.0 * atan(exp(deg2rad(-p.y() * _scale))) - M_PI/2));
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal EmptyMap::zoomIn()
|
|
|
|
{
|
|
|
|
_scale = qMax(_scale / 2.0, SCALE_MAX);
|
|
|
|
return _scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal EmptyMap::zoomOut()
|
|
|
|
{
|
|
|
|
_scale = qMin(_scale * 2.0, SCALE_MIN);
|
|
|
|
return _scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyMap::draw(QPainter *painter, const QRectF &rect)
|
|
|
|
{
|
|
|
|
painter->fillRect(rect, Qt::white);
|
|
|
|
}
|
|
|
|
|
2017-04-30 00:19:53 +02:00
|
|
|
QPointF EmptyMap::ll2xy(const Coordinates &c)
|
2017-03-18 01:30:31 +01:00
|
|
|
{
|
2017-03-29 00:17:47 +02:00
|
|
|
QPointF m = Mercator().ll2xy(c);
|
2017-03-18 01:30:31 +01:00
|
|
|
return QPointF(m.x() / _scale, m.y() / -_scale);
|
|
|
|
}
|
|
|
|
|
2017-04-30 00:19:53 +02:00
|
|
|
Coordinates EmptyMap::xy2ll(const QPointF &p)
|
2017-03-18 01:30:31 +01:00
|
|
|
{
|
|
|
|
QPointF m(p.x() * _scale, -p.y() * _scale);
|
2017-03-29 00:17:47 +02:00
|
|
|
return Mercator().xy2ll(m);
|
2017-03-18 01:30:31 +01:00
|
|
|
}
|