Situare - A location system for Facebook
Copyright (C) 2010 Ixonos Plc. Authors:
+ Sami Rämö - sami.ramo@ixonos.com
+ Jussi Laitinen - jussi.laitinen@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
USA.
*/
-#include <QtCore>
-#include <QtGlobal>
+#include <QDebug>
+#include <QString>
+#include <QStringList>
+#include <QUrl>
#include "mapengine.h"
+#include "maptile.h"
+//#include "mapscene.h"
+
++#include <QtCore>
++#include <QtGlobal>
+
-MapEngine::MapEngine(QObject *parent)
+MapEngine::MapEngine(MapView *mapView, QWidget *parent)
: QObject(parent)
{
+ m_mapView = mapView;
+ m_mapScene = new MapScene(this);
+ mapView->setScene(m_mapScene);
+ m_zoomLevel = 14;
+
+ m_mapFetcher = new MapFetcher(this);
+}
+
+void MapEngine::setViewLocation(QPointF latLonCoordinate)
+{
+ m_mapView->setZoomLevel(m_zoomLevel);
+
+ /// Show some dummy map tiles for demo purposes
+ for (int x=9351; x<=9354; x++) {
+ for (int y=4261; y<=4264; y++) {
+
+ }
+ }
+}
+
+void MapEngine::mapImageReceived(const QUrl *url, const QPixmap *pixmap)
+{
+ //QString path = "http://tile.openstreetmap.org/mapnik/14/9353/4261.png";
+ QString path = url.path();
+ qDebug() << __PRETTY_FUNCTION__ << "path:" << path;
+
+ QStringList pathParts = path.split("/", QString::SkipEmptyParts);
+ qDebug() << __PRETTY_FUNCTION__ << "pathParts:" << pathParts;
+
+// int zoom = (pathParts.at(1)).toInt();
+// int x = (pathParts.at(2)).toInt();
+// int y = (pathParts.at(3)).toInt();
+
+// MapTile *mapTile = new MapTile();
+// mapTile->setZoomLevel(zoom);
+// mapTile->setTileNumber(QPoint(x, y));
+// mapTile->setPixmap();
+// m_mapScene->addMapTile(mapTile);
}
+
+ QPoint MapEngine::latLonToTile(qreal latitude, qreal longitude, int zoom)
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+ 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);
+
+ return QPoint(qFloor(x*z), qFloor(y*z));
+ }
+
+ qreal MapEngine::tileXToLongitude(int x, int zoom)
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+ qreal z = static_cast<qreal>(1 << zoom);
+ qreal lon = x / z * 360.0 - 180.0;
+ qDebug() << lon;
+ return lon;
+ }
+
+ qreal MapEngine::tileYToLatitude(int y, int zoom)
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+ 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)));
+ }
Situare - A location system for Facebook
Copyright (C) 2010 Ixonos Plc. Authors:
+ Sami Rämö - sami.ramo@ixonos.com
+ Jussi Laitinen - jussi.laitinen@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
#ifndef MAPENGINE_H
#define MAPENGINE_H
+#include <math.h>
+
+ #include <QtCore>
+
-/**
-* @brief MapEngine controls Map.
-*
-* @class MapEngine mapengine.h "map/mapengine.h"
-*/
+#include "mapview.h"
+#include "mapscene.h"
+
+
+/// \brief Map engine
+///
+/// Logic for controlling map functionality. Does also include static methods for
+/// converting coordinates.
+/// \author Sami Rämö - sami.ramo (at) ixonos.com
class MapEngine : public QObject
{
Q_OBJECT
-
public:
- /**
- * @brief Constructor for the MapEngine.
- *
- * @fn MapEngine
- * @param parent QObject
- */
- MapEngine(QObject *parent = 0);
+ /// \brief Constructor
+ ///
+ /// \param mapView View for map
+ /// \param parent Parent
+ /// Does create and add scene to map view.
+ MapEngine(MapView *mapView, QWidget *parent = 0);
+
+ /// \brief Convert tile x & y numbers to MapScene coordinates
+ ///
+ /// \param zoomLevel Zoom level
+ /// \param tileNumber x & y number of the tile
+ /// \return MapScene coordinate
+ static QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber)
+ {
+ int x = tileNumber.x() * TILE_SIZE_X * pow(2, MAX_ZOOM_LEVEL - zoomLevel);
+ int y = tileNumber.y() * TILE_SIZE_Y * pow(2, MAX_ZOOM_LEVEL - zoomLevel);
+
+ return QPoint(x, y);
+ }
+
+ /// \brief Set view location
+ ///
+ /// \param latLonCoordinate Latitude & longitude coordinates for location
+ void setViewLocation(QPointF latLonCoordinate);
- /**
- * @brief Transforms coordinates to tile x,y values.
- *
- * @fn latLonToTile
- * @param latitude latitude value
- * @param longitude longitude value
- * @param zoom zoom level
- * @return QPoint tile x,y
- */
+ QPoint latLonToTile(qreal latitude, qreal longitude, int zoom);
+
+ /**
+ * @brief Transforms tile x value to longitude.
+ *
+ * @fn tileXToLongitude
+ * @param x tile x value
+ * @param zoom zoom value
+ * @return qreal longitude
+ */
+ qreal tileXToLongitude(int x, int zoom);
+
+ /**
+ * @brief Transforms tile y value to latitude.
+ *
+ * @fn tileYToLatitude
+ * @param y tile y value
+ * @param zoom zoom value
+ * @return qreal latitude
+ */
+ qreal tileYToLatitude(int y, int zoom);
++
+private slots:
+ void mapImageReceived(const QUrl *url, const QPixmap *pixmap);
+
+public:
+ static const int TILE_SIZE_X = 256; ///< Tile image size in x direction
+ static const int TILE_SIZE_Y = 256; ///< Tile image size in y direction
+ static const int MIN_ZOOM_LEVEL = 0; ///< Minimum zoom level
+ static const int MAX_ZOOM_LEVEL = 18; ///< Maximum zoom level
+
+private:
+ MapView *m_mapView; ///< View for viewing map
+ MapScene *m_mapScene; ///< Scene for map tiles
+ MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
+ int m_zoomLevel; ///< Current zoom level
};
#endif // MAPENGINE_H