2017-03-18 01:30:31 +01:00
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QPainter>
|
2017-11-26 18:54:03 +01:00
|
|
|
#include "common/rectc.h"
|
2018-09-24 22:49:10 +02:00
|
|
|
#include "osm.h"
|
2017-03-18 01:30:31 +01:00
|
|
|
#include "emptymap.h"
|
|
|
|
|
|
|
|
|
2018-02-28 22:19:46 +01:00
|
|
|
#define TILE_SIZE 256
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2018-02-28 22:19:46 +01:00
|
|
|
static int limitZoom(int zoom)
|
|
|
|
{
|
2018-09-25 21:07:44 +02:00
|
|
|
if (zoom < OSM::ZOOMS.min())
|
|
|
|
return OSM::ZOOMS.min();
|
|
|
|
if (zoom > OSM::ZOOMS.max())
|
|
|
|
return OSM::ZOOMS.max();
|
2018-02-28 22:19:46 +01:00
|
|
|
|
|
|
|
return zoom;
|
|
|
|
}
|
|
|
|
|
2018-02-16 19:37:04 +01:00
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
EmptyMap::EmptyMap(QObject *parent) : Map(parent)
|
|
|
|
{
|
2018-09-25 21:07:44 +02:00
|
|
|
_zoom = OSM::ZOOMS.max();
|
2017-03-18 01:30:31 +01:00
|
|
|
}
|
|
|
|
|
2018-07-13 09:51:41 +02:00
|
|
|
QRectF EmptyMap::bounds()
|
2017-03-18 01:30:31 +01:00
|
|
|
{
|
2018-09-25 21:07:44 +02:00
|
|
|
return QRectF(ll2xy(OSM::BOUNDS.topLeft()), ll2xy(OSM::BOUNDS.bottomRight()));
|
2017-03-18 01:30:31 +01:00
|
|
|
}
|
|
|
|
|
2018-04-16 20:26:10 +02:00
|
|
|
int EmptyMap::zoomFit(const QSize &size, const RectC &rect)
|
2017-03-18 01:30:31 +01:00
|
|
|
{
|
2018-04-16 20:26:10 +02:00
|
|
|
if (!rect.isValid())
|
2018-09-25 21:07:44 +02:00
|
|
|
_zoom = OSM::ZOOMS.max();
|
2017-03-18 01:30:31 +01:00
|
|
|
else {
|
2018-09-25 21:07:44 +02:00
|
|
|
QRectF tbr(OSM::ll2m(rect.topLeft()), OSM::ll2m(rect.bottomRight()));
|
2017-03-18 01:30:31 +01:00
|
|
|
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
|
|
|
|
|
2018-09-25 21:07:44 +02:00
|
|
|
_zoom = limitZoom(OSM::scale2zoom(qMax(sc.x(), -sc.y()), TILE_SIZE));
|
2018-02-28 22:19:46 +01:00
|
|
|
}
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2018-02-28 22:19:46 +01:00
|
|
|
return _zoom;
|
2017-03-18 01:30:31 +01:00
|
|
|
}
|
|
|
|
|
2018-06-30 12:14:58 +02:00
|
|
|
qreal EmptyMap::resolution(const QRectF &rect)
|
2017-06-26 00:20:42 +02:00
|
|
|
{
|
2018-09-25 21:07:44 +02:00
|
|
|
return OSM::resolution(rect.center(), _zoom, TILE_SIZE);
|
2017-03-18 01:30:31 +01:00
|
|
|
}
|
|
|
|
|
2018-02-28 22:19:46 +01:00
|
|
|
int EmptyMap::zoomIn()
|
2017-03-18 01:30:31 +01:00
|
|
|
{
|
2018-09-25 21:07:44 +02:00
|
|
|
_zoom = qMin(_zoom + 1, OSM::ZOOMS.max());
|
2018-02-28 22:19:46 +01:00
|
|
|
return _zoom;
|
2017-03-18 01:30:31 +01:00
|
|
|
}
|
|
|
|
|
2018-02-28 22:19:46 +01:00
|
|
|
int EmptyMap::zoomOut()
|
2017-03-18 01:30:31 +01:00
|
|
|
{
|
2018-09-25 21:07:44 +02:00
|
|
|
_zoom = qMax(_zoom - 1, OSM::ZOOMS.min());
|
2018-02-28 22:19:46 +01:00
|
|
|
return _zoom;
|
2017-03-18 01:30:31 +01:00
|
|
|
}
|
|
|
|
|
2018-08-23 20:26:10 +02:00
|
|
|
void EmptyMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
2017-03-18 01:30:31 +01:00
|
|
|
{
|
2018-05-22 22:40:15 +02:00
|
|
|
Q_UNUSED(painter);
|
|
|
|
Q_UNUSED(rect);
|
2018-08-23 20:26:10 +02:00
|
|
|
Q_UNUSED(flags);
|
2017-03-18 01:30:31 +01:00
|
|
|
}
|
|
|
|
|
2018-07-13 09:51:41 +02:00
|
|
|
QPointF EmptyMap::ll2xy(const Coordinates &c)
|
2017-03-18 01:30:31 +01:00
|
|
|
{
|
2018-09-25 21:07:44 +02:00
|
|
|
qreal scale = OSM::zoom2scale(_zoom, TILE_SIZE);
|
|
|
|
QPointF m = OSM::ll2m(c);
|
2018-02-28 22:19:46 +01:00
|
|
|
return QPointF(m.x() / scale, m.y() / -scale);
|
2017-03-18 01:30:31 +01:00
|
|
|
}
|
|
|
|
|
2018-07-13 09:51:41 +02:00
|
|
|
Coordinates EmptyMap::xy2ll(const QPointF &p)
|
2017-03-18 01:30:31 +01:00
|
|
|
{
|
2018-09-25 21:07:44 +02:00
|
|
|
qreal scale = OSM::zoom2scale(_zoom, TILE_SIZE);
|
|
|
|
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale));
|
2017-03-18 01:30:31 +01:00
|
|
|
}
|