--- /dev/null
+#include <QtCore>
+#include <QtGlobal>
+
+#include "map/mapengine.h"
+
+MapEngine::MapEngine(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+QPoint MapEngine::tileFromCoordinate(qreal latitude, qreal longitude, int zoom)
+{
+ //Power of two
+ qreal z = static_cast<qreal>(1 << zoom);
+
+ qreal x = static_cast<qreal>((longitude + 180.0) / 360.0);
+ qreal y = static_cast<qreal>((1.0 - log(tan(latitude * M_PI / 180.0) + 1.0
+ / cos(latitude * M_PI / 180.0)) / M_PI) / 2.0);
+
+ qDebug() << x*z << "," << y*z;
+ return QPoint(qFloor(x*z), qFloor(y*z));
+}
+
+qreal MapEngine::longitudeFromTileX(int x, int zoom)
+{
+ qreal z = static_cast<qreal>(1 << zoom);
+ qreal lon = x / z * 360.0 - 180.0;
+ qDebug() << lon;
+ return lon;
+}
+
+qreal MapEngine::latitudeFromTileY(int y, int zoom)
+{
+ qreal z = static_cast<qreal>(1 << zoom);
+ qreal n = M_PI - 2 * M_PI * y / zoom;
+ return 180.0 / (M_PI * atan(0.5 * exp(n) - exp(-n)));
+}
--- /dev/null
+#ifndef MAPENGINE_H
+#define MAPENGINE_H
+
+#include <QtCore>
+
+
+/**
+* @brief
+*
+* @class MapEngine mapengine.h "map/mapengine.h"
+*/
+class MapEngine : public QObject
+{
+ Q_OBJECT
+
+public:
+ /**
+ * @brief Constructor for the MapEngine.
+ *
+ * @fn MapEngine
+ * @param parent QObject
+ */
+ MapEngine(QObject *parent = 0);
+
+
+ /**
+ * @brief Transforms coordinates to tile x,y values.
+ *
+ * @fn tileFromCoordinate
+ * @param latitude latitude value
+ * @param longitude longitude value
+ * @param zoom zoom level
+ * @return QPoint tile x,y
+ */
+ QPoint tileFromCoordinate(qreal latitude, qreal longitude, int zoom);
+
+ /**
+ * @brief Transforms tile x value to longitude.
+ *
+ * @fn longitudeFromTile
+ * @param x tile x value
+ * @param zoom zoom value
+ * @return qreal longitude
+ */
+ qreal longitudeFromTileX(int x, int zoom);
+
+ /**
+ * @brief Transforms tile y value to latitude.
+ *
+ * @fn latitudeFromTile
+ * @param y tile y value
+ * @param zoom zoom value
+ * @return qreal latitude
+ */
+ qreal latitudeFromTileY(int y, int zoom);
+
+};
+
+#endif // MAPENGINE_H
--- /dev/null
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QUrl>
+#include <QDebug>
+#include <QPixmap>
+
+#include "mapfetcher.h"
+
+MapFetcher::MapFetcher(QObject *parent)
+ : QObject(parent)
+{
+ connect(&m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
+}
+
+void MapFetcher::fetchMapImage(const QUrl &url)
+{
+ if (url.isEmpty())
+ return;
+
+ QNetworkRequest request(url);
+ request.setRawHeader("User-Agent", "Map Test");
+ qDebug() << request.url();
+ m_manager.get(request);
+}
+
+void MapFetcher::downloadFinished(QNetworkReply *reply)
+{
+ qDebug() << "downloadFinished()";
+ if (reply->error()) {
+ qDebug() << reply->errorString();
+ emit error(reply->errorString());
+ }
+ else {
+ QImage image;
+ QUrl url = reply->url();
+ if (!image.load(reply, 0))
+ image = QImage();
+
+ emit mapImageReceived(image);
+ }
+
+ reply->deleteLater();
+}
+
+MapFetcher::~MapFetcher()
+{
+
+}
--- /dev/null
+#ifndef MAPFETCHER_H
+#define MAPFETCHER_H
+
+#include <QtCore>
+#include <QNetworkAccessManager>
+
+class QNetworkReply;
+class QUrl;
+
+#include "mapfetcher.h"
+
+class MapFetcher : public QObject
+{
+ Q_OBJECT
+
+public:
+ MapFetcher(QObject *parent = 0);
+ ~MapFetcher();
+ void fetchMapImage(const QUrl &url);
+
+signals:
+ void mapImageReceived(const QImage &image);
+ void error(const QString &message);
+
+public slots:
+ void downloadFinished(QNetworkReply *reply);
+
+private:
+ QNetworkAccessManager m_manager;
+};
+
+#endif