Code cleanup
[GPXSee.git] / src / map / osm.cpp
blob9a2aa50b190c5b20a03c156b2af87644e9310ab4
1 #include "common/wgs84.h"
2 #include "osm.h"
5 #define EPSILON 1e-6
7 QPointF osm::ll2m(const Coordinates &c)
9 return QPointF(c.lon(), rad2deg(log(tan(M_PI_4 + deg2rad(c.lat())/2.0))));
12 Coordinates osm::m2ll(const QPointF &p)
14 return Coordinates(p.x(), rad2deg(2.0 * atan(exp(deg2rad(p.y()))) - M_PI_2));
17 QPoint osm::mercator2tile(const QPointF &m, int zoom)
19 return QPoint((int)(floor((m.x() + 180.0) / 360.0 * (1<<zoom))),
20 (int)(floor((1.0 - (m.y() / 180.0)) / 2.0 * (1<<zoom))));
23 qreal osm::zoom2scale(int zoom, int tileSize)
25 return (360.0/(qreal)((1<<zoom) * tileSize));
28 int osm::scale2zoom(qreal scale, int tileSize)
30 return (int)(log2(360.0/(scale * (qreal)tileSize)) + EPSILON);
33 qreal osm::resolution(const QPointF &p, int zoom, int tileSize)
35 qreal scale = zoom2scale(zoom, tileSize);
37 return (WGS84_RADIUS * 2.0 * M_PI * scale / 360.0
38 * cos(2.0 * atan(exp(deg2rad(-p.y() * scale))) - M_PI/2));