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)
#include <QtCore>
-#include "mapview.h"
+#include "mapfetcher.h"
#include "mapscene.h"
+#include "mapview.h"
/// \brief Map engine
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