Integrated fetching of the maps from OSM server v0.1
authorSami Rämö <sami.ramo@ixonos.com>
Thu, 1 Apr 2010 11:53:08 +0000 (14:53 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Thu, 1 Apr 2010 11:53:08 +0000 (14:53 +0300)
src/map/mapengine.cpp
src/map/mapengine.h
src/map/mapfetcher.cpp
src/map/mapfetcher.h
src/src.pro
tests/testmap/testmaptile/testmaptile.pro

index 5c57fdd..748f328 100644 (file)
@@ -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)
index 5bffa13..608f839 100644 (file)
@@ -27,8 +27,9 @@
 
 #include <QtCore>
 
-#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
index 807b2fa..e711b48 100644 (file)
@@ -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);
index 9aab8d8..e12e670 100644 (file)
@@ -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();
 
index b782baf..551631f 100644 (file)
@@ -21,7 +21,7 @@ HEADERS += ui/mainwindow.h \
     map/mapscene.h \
     map/maptile.h \
     map/mapfetcher.h
-
+QT += network
 
 # -----------------------------------------------------------------
 # Debian packetizing additions
index 70c9a69..8526f70 100644 (file)
@@ -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 += .