2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
6 Jussi Laitinen - jussi.laitinen@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
29 #include "mapfetcher.h"
36 * Logic for controlling map functionality. Does also include static methods for
37 * converting coordinates.
38 * @author Sami Rämö - sami.ramo (at) ixonos.com
40 class MapEngine : public QObject
47 * @param parent Parent
49 MapEngine(QWidget *parent = 0);
52 * @brief Convert tile x & y numbers to MapScene coordinates
54 * @param zoomLevel Zoom level
55 * @param tileNumber x & y numbers of the tile
56 * @return QPoint MapScene coordinate
59 static QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber)
61 int pow = 1 << (MAX_ZOOM_LEVEL - zoomLevel);
62 int x = tileNumber.x() * TILE_SIZE_X * pow;
63 int y = tileNumber.y() * TILE_SIZE_Y * pow;
69 * @brief Getter for scene
71 * @return QGraphicsScene
73 QGraphicsScene* scene();
76 * @brief Set view location
78 * @param latLonCoordinate Latitude & longitude coordinates for location
80 void setViewLocation(QPointF latLonCoordinate);
83 * @brief Converts latitude, longitude and zoom to tile x, y values.
85 * @param zoomLevel zoom level
86 * @param latLonCoordinate latitude and longitude values
87 * @return QPoint tile x,y value
89 static QPoint convertLatLonToTile(int zoomLevel, QPointF latLonCoordinate) {
90 qDebug() << __PRETTY_FUNCTION__;
92 qreal longitude = latLonCoordinate.x();
93 qreal latitude = latLonCoordinate.y();
95 qreal z = static_cast<qreal>(1 << zoomLevel);
97 qreal x = static_cast<qreal>((longitude + 180.0) / 360.0);
98 qreal y = static_cast<qreal>((1.0 - log(tan(latitude * M_PI / 180.0) + 1.0
99 / cos(latitude * M_PI / 180.0)) / M_PI) / 2.0);
101 return QPoint(qFloor(x*z), qFloor(y*z));
106 * @brief Build URL for donwloading single map tile from OpenStreetMap tile server
108 * @param zoomLevel Zoom level
109 * @param tileNumbers Tile x & y numbers
110 * @return URL for the required tile
112 QUrl buildURL(int zoomLevel, QPoint tileNumbers);
115 * @brief Parses given URL to zoom, x and y values. Parsed values are
116 * placed in variables given as parameters.
118 * @param url url to parse
119 * @param [out] zoom zoom variable
120 * @param [out] x x variable
121 * @param [out] y y variable
123 void parseURL(const QUrl &url, int &zoom, int &x, int &y);
127 * @brief Slot for received map tile images
129 * Does add MapTile objects to MapScene. Zoom level and location is parsed from URL.
130 * @param url URL of the received image
131 * @param pixmap Received pixmap
133 void mapImageReceived(const QUrl &url, const QPixmap &pixmap);
137 * @brief Signal for zoom level change
139 * @param newZoomLevel New zoom level
141 void zoomLevelChanged(int newZoomLevel);
144 MapScene *m_mapScene; ///< Scene for map tiles
145 MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
146 int m_zoomLevel; ///< Current zoom level
149 #endif // MAPENGINE_H