3 #include "common/coordinates.h"
4 #include "common/rectc.h"
5 #include "common/wgs84.h"
13 static QPointF
ll2m(const Coordinates
&c
)
15 return QPointF(c
.lon(), rad2deg(log(tan(M_PI_4
+ deg2rad(c
.lat())/2.0))));
18 static Coordinates
m2ll(const QPointF
&p
)
20 return Coordinates(p
.x(), rad2deg(2.0 * atan(exp(deg2rad(p
.y()))) - M_PI_2
));
23 static qreal
zoom2scale(int zoom
)
25 return (360.0/(qreal
)((1<<zoom
) * TILE_SIZE
));
28 static int scale2zoom(qreal scale
)
30 return (int)log2(360.0/(scale
* (qreal
)TILE_SIZE
));
33 static int limitZoom(int zoom
)
44 EmptyMap::EmptyMap(QObject
*parent
) : Map(parent
)
49 QRectF
EmptyMap::bounds() const
51 return QRectF(ll2xy(Coordinates(-180, 85)), ll2xy(Coordinates(180, -85)));
54 int EmptyMap::zoomFit(const QSize
&size
, const RectC
&rect
)
59 QRectF
tbr(ll2m(rect
.topLeft()), ll2m(rect
.bottomRight()));
60 QPointF
sc(tbr
.width() / size
.width(), tbr
.height() / size
.height());
62 _zoom
= limitZoom(scale2zoom(qMax(sc
.x(), -sc
.y())));
68 qreal
EmptyMap::resolution(const QRectF
&rect
)
70 qreal scale
= zoom2scale(_zoom
);
72 return (WGS84_RADIUS
* 2.0 * M_PI
* scale
/ 360.0
73 * cos(2.0 * atan(exp(deg2rad(-rect
.center().y() * scale
))) - M_PI
/2));
76 int EmptyMap::zoomIn()
78 _zoom
= qMin(_zoom
+ 1, ZOOM_MAX
);
82 int EmptyMap::zoomOut()
84 _zoom
= qMax(_zoom
- 1, ZOOM_MIN
);
88 void EmptyMap::draw(QPainter
*painter
, const QRectF
&rect
, bool block
)
95 QPointF
EmptyMap::ll2xy(const Coordinates
&c
) const
97 qreal scale
= zoom2scale(_zoom
);
99 return QPointF(m
.x() / scale
, m
.y() / -scale
);
102 Coordinates
EmptyMap::xy2ll(const QPointF
&p
) const
104 qreal scale
= zoom2scale(_zoom
);
105 return m2ll(QPointF(p
.x() * scale
, -p
.y() * scale
));