Modified mapEngine and mapFetcher.
[situare] / src / map / mapengine.cpp
1 #include <QtCore>
2 #include <QtGlobal>
3
4 #include "mapengine.h"
5
6 MapEngine::MapEngine(QObject *parent)
7     : QObject(parent)
8 {
9
10 }
11
12 /*QPoint MapEngine::latLonToTile(qreal latitude, qreal longitude, int zoom)
13 {
14     //Power of two
15     qreal z = static_cast<qreal>(1 << zoom);
16
17     qreal x = static_cast<qreal>((longitude + 180.0) / 360.0);
18     qreal y = static_cast<qreal>((1.0 - log(tan(latitude * M_PI / 180.0) + 1.0
19                                 / cos(latitude * M_PI / 180.0)) / M_PI) / 2.0);
20
21     return QPoint(qFloor(x*z), qFloor(y*z));
22 }*/
23
24 qreal MapEngine::tileXToLongitude(int x, int zoom)
25 {
26     qreal z = static_cast<qreal>(1 << zoom);
27     qreal lon = x / z * 360.0 - 180.0;
28     qDebug() << lon;
29     return lon;
30 }
31
32 qreal MapEngine::tileYToLatitude(int y, int zoom)
33 {
34     qreal z = static_cast<qreal>(1 << zoom);
35     qreal n = M_PI - 2 * M_PI * y / zoom;
36     return 180.0 / (M_PI * atan(0.5 * exp(n) - exp(-n)));
37 }