From: Sami Rämö Date: Thu, 1 Apr 2010 10:57:12 +0000 (+0300) Subject: Merge branch 'laitiju' into map X-Git-Tag: v0.1~2 X-Git-Url: https://vcs.maemo.org/git/?p=situare;a=commitdiff_plain;h=f4331f2523128a945d3178737a3aeb54d073423f Merge branch 'laitiju' into map Conflicts: src/map/mapengine.cpp src/map/mapengine.h src/src.pro tests/testmap/testmapscene/testmapscene.pro tests/testmap/testmaptile/testmaptile.pro tests/testmap/testmapview/testmapview.cpp tests/testmap/testmapview/testmapview.pro --- f4331f2523128a945d3178737a3aeb54d073423f diff --cc src/map/mapengine.cpp index 3f68907,b8e37bf..5c57fdd --- a/src/map/mapengine.cpp +++ b/src/map/mapengine.cpp @@@ -2,7 -2,7 +2,8 @@@ 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 @@@ -19,54 -19,41 +20,86 @@@ USA. */ -#include -#include +#include +#include +#include +#include #include "mapengine.h" +#include "maptile.h" +//#include "mapscene.h" + ++#include ++#include + -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(1 << zoom); + + qreal x = static_cast((longitude + 180.0) / 360.0); + qreal y = static_cast((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(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(1 << zoom); + qreal n = M_PI - 2 * M_PI * y / zoom; + return 180.0 / (M_PI * atan(0.5 * exp(n) - exp(-n))); + } diff --cc src/map/mapengine.h index 54acd78,bf35183..5bffa13 --- a/src/map/mapengine.h +++ b/src/map/mapengine.h @@@ -2,7 -2,7 +2,8 @@@ 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 @@@ -22,62 -22,56 +23,84 @@@ #ifndef MAPENGINE_H #define MAPENGINE_H +#include + + #include + -/** -* @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 diff --cc src/src.pro index 37136c4,631b02d..b782baf --- a/src/src.pro +++ b/src/src.pro @@@ -7,19 -7,11 +7,21 @@@ SOURCES += main.cpp ui/mainwindow.cpp \ ui/mapviewscreen.cpp \ ui/listviewscreen.cpp \ - src/map/mapfetcher.cpp + map/mapengine.cpp \ + map/mapview.cpp \ + map/mapscene.cpp \ - map/maptile.cpp ++ map/maptile.cpp \ ++ map/mapfetcher.cpp + HEADERS += ui/mainwindow.h \ ui/mapviewscreen.h \ ui/listviewscreen.h \ - src/map/mapfetcher.h + map/mapengine.h \ + map/mapview.h \ + map/mapscene.h \ - map/maptile.h ++ map/maptile.h \ ++ map/mapfetcher.h + # ----------------------------------------------------------------- # Debian packetizing additions