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(QWidget *parent)
38 m_mapScene = new MapScene(this);
41 m_mapFetcher = new MapFetcher(new QNetworkAccessManager(this), this);
42 connect(m_mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)), this,
43 SLOT(mapImageReceived(QUrl, QPixmap)));
46 void MapEngine::setViewLocation(QPointF latLonCoordinate)
48 emit zoomLevelChanged(m_zoomLevel);
50 /// Fetch some map tiles for demo purposes
51 for (int x=9351; x<=9354; x++) {
52 for (int y=4261; y<=4264; y++) {
53 QUrl url = buildURL(m_zoomLevel, QPoint(x, y));
54 m_mapFetcher->fetchMapImage(url);
59 QUrl MapEngine::buildURL(int zoomLevel, QPoint tileNumbers)
61 QString url = QString("http://tile.openstreetmap.org/mapnik/%1/%2/%3.png")
62 .arg(zoomLevel).arg(tileNumbers.x()).arg(tileNumbers.y());
67 void MapEngine::parseURL(const QUrl &url, int &zoom, int &x, int &y)
69 QString path = url.path();
70 QStringList pathParts = path.split("/", QString::SkipEmptyParts);
72 zoom = (pathParts.at(1)).toInt();
73 x = (pathParts.at(2)).toInt();
74 QString yString = pathParts.at(3);
80 void MapEngine::mapImageReceived(const QUrl &url, const QPixmap &pixmap)
86 parseURL(url, zoom, x, y);
88 MapTile *mapTile = new MapTile();
89 mapTile->setZoomLevel(zoom);
90 mapTile->setTileNumber(QPoint(x, y));
91 mapTile->setPixmap(pixmap);
92 m_mapScene->addMapTile(mapTile);
95 QGraphicsScene* MapEngine::scene()
97 return dynamic_cast<QGraphicsScene *>(m_mapScene);