From 557f3ff8125ebf7308aaebb74bd0760c3fbfe887 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sami=20R=C3=A4m=C3=B6?= Date: Thu, 1 Apr 2010 14:53:08 +0300 Subject: [PATCH] Integrated fetching of the maps from OSM server --- src/map/mapengine.cpp | 37 +++++++++++++++++------------ src/map/mapengine.h | 13 ++++++++-- src/map/mapfetcher.cpp | 2 +- src/map/mapfetcher.h | 2 +- src/src.pro | 2 +- tests/testmap/testmaptile/testmaptile.pro | 1 + 6 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/map/mapengine.cpp b/src/map/mapengine.cpp index 5c57fdd..748f328 100644 --- a/src/map/mapengine.cpp +++ b/src/map/mapengine.cpp @@ -40,39 +40,46 @@ MapEngine::MapEngine(MapView *mapView, QWidget *parent) mapView->setScene(m_mapScene); m_zoomLevel = 14; - m_mapFetcher = new MapFetcher(this); + m_mapFetcher = new MapFetcher(new QNetworkAccessManager(this), this); + connect(m_mapFetcher, SIGNAL(mapImageReceived(QUrl,QPixmap)), this, + SLOT(mapImageReceived(QUrl, QPixmap))); } void MapEngine::setViewLocation(QPointF latLonCoordinate) { m_mapView->setZoomLevel(m_zoomLevel); - /// Show some dummy map tiles for demo purposes + /// Fetch some map tiles for demo purposes for (int x=9351; x<=9354; x++) { for (int y=4261; y<=4264; y++) { - + QString url = QString("http://tile.openstreetmap.org/mapnik/%1/%2/%3.png") + .arg(m_zoomLevel).arg(x).arg(y); + m_mapFetcher->fetchMapImage(QUrl(url)); } } } -void MapEngine::mapImageReceived(const QUrl *url, const QPixmap *pixmap) +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; + //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(); + int zoom = (pathParts.at(1)).toInt(); + int x = (pathParts.at(2)).toInt(); + QString yString = pathParts.at(3); + yString.chop(4); + int y = yString.toInt(); + + //qDebug() << __PRETTY_FUNCTION__ << zoom << x << y; -// MapTile *mapTile = new MapTile(); -// mapTile->setZoomLevel(zoom); -// mapTile->setTileNumber(QPoint(x, y)); -// mapTile->setPixmap(); -// m_mapScene->addMapTile(mapTile); + MapTile *mapTile = new MapTile(); + mapTile->setZoomLevel(zoom); + mapTile->setTileNumber(QPoint(x, y)); + mapTile->setPixmap(pixmap); + m_mapScene->addMapTile(mapTile); } QPoint MapEngine::latLonToTile(qreal latitude, qreal longitude, int zoom) diff --git a/src/map/mapengine.h b/src/map/mapengine.h index 5bffa13..608f839 100644 --- a/src/map/mapengine.h +++ b/src/map/mapengine.h @@ -27,8 +27,9 @@ #include -#include "mapview.h" +#include "mapfetcher.h" #include "mapscene.h" +#include "mapview.h" /// \brief Map engine @@ -88,7 +89,15 @@ public: qreal tileYToLatitude(int y, int zoom); private slots: - void mapImageReceived(const QUrl *url, const QPixmap *pixmap); + /** + * @brief Slot for received map tile images + * + * Does add MapTile objects to MapScene. Zoom level and location is parsed from URL. + * @fn mapImageReceived + * @param url URL of the received image + * @param pixmap Received pixmap + */ + void mapImageReceived(const QUrl &url, const QPixmap &pixmap); public: static const int TILE_SIZE_X = 256; ///< Tile image size in x direction diff --git a/src/map/mapfetcher.cpp b/src/map/mapfetcher.cpp index 807b2fa..e711b48 100644 --- a/src/map/mapfetcher.cpp +++ b/src/map/mapfetcher.cpp @@ -32,7 +32,7 @@ static int MAX_PARALLEL_DOWNLOADS = 2; -MapFetcher::MapFetcher(QObject *parent, QNetworkAccessManager *manager) +MapFetcher::MapFetcher(QNetworkAccessManager *manager, QObject *parent) : QObject(parent), m_manager(manager) { QNetworkDiskCache *diskCache = new QNetworkDiskCache(this); diff --git a/src/map/mapfetcher.h b/src/map/mapfetcher.h index 9aab8d8..e12e670 100644 --- a/src/map/mapfetcher.h +++ b/src/map/mapfetcher.h @@ -48,7 +48,7 @@ public: * @fn MapFetcher * @param parent parent object */ - MapFetcher(QObject *parent = 0, QNetworkAccessManager *manager = 0); + MapFetcher(QNetworkAccessManager *manager, QObject *parent = 0); ~MapFetcher(); diff --git a/src/src.pro b/src/src.pro index b782baf..551631f 100644 --- a/src/src.pro +++ b/src/src.pro @@ -21,7 +21,7 @@ HEADERS += ui/mainwindow.h \ map/mapscene.h \ map/maptile.h \ map/mapfetcher.h - +QT += network # ----------------------------------------------------------------- # Debian packetizing additions diff --git a/tests/testmap/testmaptile/testmaptile.pro b/tests/testmap/testmaptile/testmaptile.pro index 70c9a69..8526f70 100644 --- a/tests/testmap/testmaptile/testmaptile.pro +++ b/tests/testmap/testmaptile/testmaptile.pro @@ -2,6 +2,7 @@ # Automatically generated by qmake (2.01a) Mon Mar 29 10:06:28 2010 # ##################################################################### CONFIG += qtestlib +QT += network TEMPLATE = app TARGET = DEPENDPATH += . -- 1.7.9.5