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,
25 #include <QStringList>
28 #include "mapengine.h"
30 //#include "mapscene.h"
35 MapEngine::MapEngine(MapView *mapView, QWidget *parent)
39 m_mapScene = new MapScene(this);
40 mapView->setScene(m_mapScene);
43 m_mapFetcher = new MapFetcher(this);
46 void MapEngine::setViewLocation(QPointF latLonCoordinate)
48 m_mapView->setZoomLevel(m_zoomLevel);
50 /// Show some dummy map tiles for demo purposes
51 for (int x=9351; x<=9354; x++) {
52 for (int y=4261; y<=4264; y++) {
58 void MapEngine::mapImageReceived(const QUrl *url, const QPixmap *pixmap)
60 //QString path = "http://tile.openstreetmap.org/mapnik/14/9353/4261.png";
61 QString path = url.path();
62 qDebug() << __PRETTY_FUNCTION__ << "path:" << path;
64 QStringList pathParts = path.split("/", QString::SkipEmptyParts);
65 qDebug() << __PRETTY_FUNCTION__ << "pathParts:" << pathParts;
67 // int zoom = (pathParts.at(1)).toInt();
68 // int x = (pathParts.at(2)).toInt();
69 // int y = (pathParts.at(3)).toInt();
71 // MapTile *mapTile = new MapTile();
72 // mapTile->setZoomLevel(zoom);
73 // mapTile->setTileNumber(QPoint(x, y));
74 // mapTile->setPixmap();
75 // m_mapScene->addMapTile(mapTile);
78 QPoint MapEngine::latLonToTile(qreal latitude, qreal longitude, int zoom)
80 qDebug() << __PRETTY_FUNCTION__;
81 qreal z = static_cast<qreal>(1 << zoom);
83 qreal x = static_cast<qreal>((longitude + 180.0) / 360.0);
84 qreal y = static_cast<qreal>((1.0 - log(tan(latitude * M_PI / 180.0) + 1.0
85 / cos(latitude * M_PI / 180.0)) / M_PI) / 2.0);
87 return QPoint(qFloor(x*z), qFloor(y*z));
90 qreal MapEngine::tileXToLongitude(int x, int zoom)
92 qDebug() << __PRETTY_FUNCTION__;
93 qreal z = static_cast<qreal>(1 << zoom);
94 qreal lon = x / z * 360.0 - 180.0;
99 qreal MapEngine::tileYToLatitude(int y, int zoom)
101 qDebug() << __PRETTY_FUNCTION__;
102 qreal z = static_cast<qreal>(1 << zoom);
103 qreal n = M_PI - 2 * M_PI * y / zoom;
104 return 180.0 / (M_PI * atan(0.5 * exp(n) - exp(-n)));