1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 23:03:22 +02:00
GPXSee/src/map/emptymap.cpp

81 lines
1.6 KiB
C++
Raw Normal View History

#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"
#include "emptymap.h"
#define TILE_SIZE 256
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();
return zoom;
}
EmptyMap::EmptyMap(QObject *parent) : Map(parent)
{
2018-09-25 21:07:44 +02:00
_zoom = OSM::ZOOMS.max();
}
2018-07-13 09:51:41 +02:00
QRectF EmptyMap::bounds()
{
2018-09-25 21:07:44 +02:00
return QRectF(ll2xy(OSM::BOUNDS.topLeft()), ll2xy(OSM::BOUNDS.bottomRight()));
}
int EmptyMap::zoomFit(const QSize &size, const RectC &rect)
{
if (!rect.isValid())
2018-09-25 21:07:44 +02:00
_zoom = OSM::ZOOMS.max();
else {
2018-09-25 21:07:44 +02:00
QRectF tbr(OSM::ll2m(rect.topLeft()), OSM::ll2m(rect.bottomRight()));
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));
}
return _zoom;
}
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);
}
int EmptyMap::zoomIn()
{
2018-09-25 21:07:44 +02:00
_zoom = qMin(_zoom + 1, OSM::ZOOMS.max());
return _zoom;
}
int EmptyMap::zoomOut()
{
2018-09-25 21:07:44 +02:00
_zoom = qMax(_zoom - 1, OSM::ZOOMS.min());
return _zoom;
}
2018-08-23 20:26:10 +02:00
void EmptyMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
{
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);
}
2018-07-13 09:51:41 +02:00
QPointF EmptyMap::ll2xy(const Coordinates &c)
{
2018-09-25 21:07:44 +02:00
qreal scale = OSM::zoom2scale(_zoom, TILE_SIZE);
QPointF m = OSM::ll2m(c);
return QPointF(m.x() / scale, m.y() / -scale);
}
2018-07-13 09:51:41 +02:00
Coordinates EmptyMap::xy2ll(const QPointF &p)
{
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));
}