Mapping of higher than current zoom level MapTiles
[situare] / src / map / mapengine.h
index 9136533..beebbf9 100644 (file)
@@ -28,6 +28,7 @@
 #include "common.h"
 #include "mapfetcher.h"
 #include "mapscene.h"
+#include "maptile.h"
 
 /**
 * @brief Map engine
@@ -66,13 +67,22 @@ public:
 
     static QPoint convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber)
     {
-        int pow = 1 << (MAX_ZOOM_LEVEL - zoomLevel);
+        int pow = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
         int x = tileNumber.x() * TILE_SIZE_X * pow;
         int y = tileNumber.y() * TILE_SIZE_Y * pow;
 
         return QPoint(x, y);
     }
 
+    static QPoint convertSceneCoordinateToTileNumber(int zoomLevel, QPointF sceneCoordinate)
+    {
+        int pow = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
+        int x = static_cast<int>(sceneCoordinate.x() / (TILE_SIZE_X*pow));
+        int y = static_cast<int>(sceneCoordinate.y() / (TILE_SIZE_Y*pow));
+
+        return QPoint(x, y);
+    }
+
     /**
     * @brief Getter for scene
     *
@@ -91,7 +101,6 @@ public:
     /**
     * @brief Converts latitude, longitude and zoom to tile x, y values.
     *
-    * @param zoomLevel zoom level
     * @param latLonCoordinate latitude and longitude values
     * @return QPoint tile x,y value
     */
@@ -108,7 +117,7 @@ public:
         if ((latitude > MAX_LATITUDE) || (latitude < MIN_LATITUDE))
             return QPoint(UNDEFINED, UNDEFINED);
 
-        qreal z = static_cast<qreal>(1 << MAX_ZOOM_LEVEL);
+        qreal z = static_cast<qreal>(1 << MAX_MAP_ZOOM_LEVEL);
 
         qreal x = static_cast<qreal>((longitude + 180.0) / 360.0);
         qreal y = static_cast<qreal>((1.0 - log(tan(latitude * M_PI / 180.0) + 1.0
@@ -117,6 +126,17 @@ public:
         return QPointF(x*z*TILE_SIZE_X, y*z*TILE_SIZE_Y);
     }
 
+    QRect calculateGrid(QPointF sceneCoordinate);
+
+public slots:
+    /**
+    * @brief Slot for setting current view location
+    *
+    * Emits locationChanged signal.
+    * @param sceneCoordinate Scene coordinates for new position
+    */
+    void setLocation(QPointF sceneCoordinate);
+
 private:
     /**
     * @brief Build URL for donwloading single map tile from OpenStreetMap tile server
@@ -138,6 +158,19 @@ private:
     */
     void parseURL(const QUrl &url, int &zoom, int &x, int &y);
 
+    /**
+    * @brief Set zValues for all tiles in the scene
+    *
+    * Drawing order of MapTiles, which has the zoom level higher than the current
+    * zoom level, is reversed and those MapTiles are mapped between lower level MapTiles.
+    * Example: If maximum zoom level is 18 and current view zoomlevel is 15, then
+    * the drawing order from top to bottom is 15, 16, 14, 17, 13, 18, 12, 11, 10, ...
+    */
+    void setZValues();
+
+    int tileMaxValue(int zoomLevel);
+
+
 private slots:
     /**
     * @brief Slot for received map tile images
@@ -148,13 +181,19 @@ private slots:
     */
     void mapImageReceived(const QUrl &url, const QPixmap &pixmap);
 
+    void viewResized(const QSize &size);
+
     /**
-    * @brief Slot for setting current view location
+    * @brief Slot for zooming in
     *
-    * Emits locationChanged signal.
-    * @param sceneCoordinate Scene coordinates for new position
     */
-    void setLocation(QPointF sceneCoordinate);
+    void zoomIn();
+
+    /**
+    * @brief Slot for zooming out
+    *
+    */
+    void zoomOut();
 
 signals:
     /**
@@ -171,10 +210,20 @@ signals:
     */
     void zoomLevelChanged(int newZoomLevel);
 
+    void fetchImage(const QUrl &url);
+
+    void centerToSceneCoordinates(QPointF sceneCoordinate);
+
 private:
+
+    void calculateTileGrid();
+
     MapScene *m_mapScene; ///< Scene for map tiles
     MapFetcher *m_mapFetcher; ///< Fetcher for map tiles
     int m_zoomLevel; ///< Current zoom level
+    QHash<QString, MapTile *> mapTilesInScene;  ///< List of map tiles in map scene
+    QSize m_viewSize;
+    QPointF m_sceneCoordinate;
 };
 
 #endif // MAPENGINE_H