*.moc
*.pro.user
Makefile
+Situare
USA.
*/
-#include <math.h>
+#include <QDebug>
#include "mapengine.h"
#include "maptile.h"
+#include "mapscene.h"
MapEngine::MapEngine()
{
MapEngine::MapEngine(MapView *mapView)
{
-// m_mapView = mapView;
-// m_mapScene = new MapScene();
-// mapView->setScene(m_mapScene);
-//
-// /// \todo remove debug data
-// for (int x=4261; x<=4264; x++) {
-// for (int y=9352; y<=9353; y++) {
-// MapTile *mapTile = new MapTile();
-// mapTile->setZoomLevel(14);
-// mapTile->setTileXY(x, y);
-// mapTile->setPixmap(QPixmap("/home/ramosam-local/situare/src/map/static_test_tiles/14_9352_4261.png"));
-// mapTile->setOffset((x-4261)*256, (y-9352)*256);
-// m_mapScene->addMapTile(mapTile);
-// }
-// }
+ m_mapView = mapView;
+ m_mapScene = new MapScene();
+ mapView->setScene(m_mapScene);
}
-QPoint MapEngine::convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber)
+void MapEngine::setViewLocation(QPointF latLonCoordinate)
{
- int x = tileNumber.x() * TILE_SIZE_X * pow(2, MAX_ZOOM_LEVEL - zoomLevel);
- int y = tileNumber.y() * TILE_SIZE_Y * pow(2, MAX_ZOOM_LEVEL - zoomLevel);
-
- return QPoint(x, y);
+ /*
+ * Add some dummy map tiles for demo purposes
+ */
+
+ for (int x=4261; x<=4264; x++) {
+ for (int y=9352; y<=9353; y++) {
+ MapTile *mapTile = new MapTile();
+ mapTile->setZoomLevel(14);
+ mapTile->setTileNumber(QPoint(x, y));
+ QString fileName = QString("../../../res/images/test_map_tiles/%1_%2_%3.png").arg(mapTile->zoomLevel()).arg(y).arg(x);
+ //QString fileName = QString("/home/ramosam-local/situare/res/images/test_map_tiles/%1_%2_%3.png").arg(mapTile->zoomLevel()).arg(y).arg(x);
+ //QString fileName = QString("/home/ramosam-local/situare/res/images/test_map_tiles/14_9352_4261.png");
+ qDebug() << __PRETTY_FUNCTION__ << "fileName:" << fileName;
+ mapTile->setPixmap(QPixmap(fileName));
+ m_mapScene->addMapTile(mapTile);
+ }
+ }
}
#ifndef MAPENGINE_H
#define MAPENGINE_H
+#include <math.h>
+
#include "mapview.h"
#include "mapscene.h"
public:
MapEngine();
MapEngine(MapView *mapView);
- QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber);
+ static QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber)
+ {
+ int x = tileNumber.x() * TILE_SIZE_X * pow(2, MAX_ZOOM_LEVEL - zoomLevel);
+ int y = tileNumber.y() * TILE_SIZE_Y * pow(2, MAX_ZOOM_LEVEL - zoomLevel);
+
+ return QPoint(x, y);
+ }
+ void setViewLocation(QPointF latLonCoordinate);
public:
static const int TILE_SIZE_X = 256;
USA.
*/
+#include <QDebug>
#include "mapscene.h"
+#include "mapengine.h"
MapScene::MapScene(QObject *parent) : QGraphicsScene(parent)
{
void MapScene::addMapTile(MapTile *mapTile)
{
-// /// \todo set offset & transfor (=zoom)
-// mapTile->setOffset(x, y);
-// //mapTile->setTransform();
-// addItem(mapTile);
+ mapTile->setOffset(MapEngine::convertTileNumberToSceneCoordinate(mapTile->zoomLevel(), mapTile->tileNumber()));
+ qDebug() << __PRETTY_FUNCTION__ << "offset" << mapTile->offset();
+
+ /// \todo set map tile strechh with mapTile->setTransform();
+ addItem(mapTile);
}
#include <QGraphicsScene>
-#include "map/maptile.h"
+#include "maptile.h"
class MapScene : public QGraphicsScene
# Input
SOURCES += testmapengine.cpp \
- ../../../src/map/mapengine.cpp
-HEADERS += ../../../src/map/mapengine.h
+ ../../../src/map/mapengine.cpp \
+ ../../../src/map/mapscene.cpp \
+ ../../../src/map/maptile.cpp \
+ ../../../src/map/mapview.cpp
+HEADERS += ../../../src/map/mapengine.h \
+ ../../../src/map/mapscene.h \
+ ../../../src/map/maptile.h \
+ ../../../src/map/mapview.h
+RESOURCES +=
Q_OBJECT
private slots:
void convertTileNumberToSceneCoordinate();
+ void setViewLocation();
};
void TestMapEngine::convertTileNumberToSceneCoordinate()
QCOMPARE(mapEngine.convertTileNumberToSceneCoordinate(16, QPoint(3,4)), QPoint(3072,4096));
}
+void TestMapEngine::setViewLocation()
+{
+ MapView mapView;
+ MapEngine mapEngine(&mapView);
+
+ mapEngine.setViewLocation(QPointF(25.0000, 65.0000));
+}
+
QTEST_MAIN(TestMapEngine)
#include "testmapengine.moc"
#include <QtTest/QtTest>
+#include <QDebug>
#include "map/mapscene.h"
#include "map/maptile.h"
+#include "map/mapengine.h"
class TestMapScene : public QObject
{
{
MapScene mapScene;
- MapTile mapTile;
- mapTile.setZoomLevel(18);
- mapTile.setTileNumber(QPoint(12, 47));
+ /*
+ Zoom level is 18, so no stretching should occure
+ Top-left corner 256, 512
+ Bottom-right corner 511, 767
+ */
+ MapTile *mapTile = new MapTile();
+ mapTile->setZoomLevel(18);
+ mapTile->setTileNumber(QPoint(1, 2));
+ mapTile->setPixmap(QPixmap("maptile.png"));
- mapScene.addMapTile(&mapTile);
+ mapScene.addMapTile(mapTile);
- QVERIFY(mapTile.zoomLevel() == 13);
+ int x = 256;
+ int y = 512;
+
+// QList<QGraphicsItem *> items = mapScene.items();
+// qDebug() << "items.count()" << items.count();
+
+ /*
+ Check around top-left and bottom-right corners
+ */
+ QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
+ QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
+ QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(mapTile));
+ QCOMPARE(mapScene.itemAt(x+255, y+255), dynamic_cast<QGraphicsItem *>(mapTile));
+ QCOMPARE(mapScene.itemAt(x+256, y+255), (QGraphicsItem *)0);
+ QCOMPARE(mapScene.itemAt(x+255, y+256), (QGraphicsItem *)0);
}
QTEST_MAIN(TestMapScene)
{
Q_OBJECT
private slots:
- void dummyTestCase();
+// void dummyTestCase();
};
-void TestMapView::dummyTestCase()
-{
- QVERIFY(true);
-}
+//void TestMapView::dummyTestCase()
+//{
+// QVERIFY(true);
+//}
QTEST_MAIN(TestMapView)
#include "testmapview.moc"