Modified MapView viewportUpdateMode.
[situare] / src / map / mapengine.h
index 1d9cd98..d64a6a4 100644 (file)
@@ -126,8 +126,6 @@ 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
@@ -137,6 +135,8 @@ public slots:
     */
     void setLocation(QPointF sceneCoordinate);
 
+    void viewResized(const QSize &size);
+
 private:
     /**
     * @brief Build URL for donwloading single map tile from OpenStreetMap tile server
@@ -158,8 +158,47 @@ 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);
 
+    /**
+    * @brief Calculates grid of tile coordinates from current scene coordinate.
+    *
+    * Grid size is calculated from view size and scene's current center coordinate.
+    *
+    * @param sceneCoordinate scene's current center coordinate
+    * @return QRect grid of tile coordinates
+    */
+    QRect calculateGrid(QPointF sceneCoordinate);
+
+    /**
+    * @brief Calculate new tiles to fetch.
+    *
+    * @param sceneCoordinate scene's center coordinate
+    */
+    void calculateNewTiles(QPointF sceneCoordinate);
+
+    /**
+    * @brief Removes tiles which are out of view bounds.
+    */
+    void removeOldTiles();
+
+    /**
+    * @brief Checks if center tile has changed.
+    *
+    * @param sceneCoordinate scene's center coordinate
+    * @return bool true if center tile changed, false otherwise
+    */
+    bool centerTileChanged(QPointF sceneCoordinate);
 
 private slots:
     /**
@@ -171,8 +210,6 @@ private slots:
     */
     void mapImageReceived(const QUrl &url, const QPixmap &pixmap);
 
-    void viewResized(const QSize &size);
-
     /**
     * @brief Slot for zooming in
     *
@@ -206,14 +243,15 @@ signals:
 
 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;
+    QQueue<QString> mapTilesInView;
+    QPoint m_centerTile;
+    QRect viewGrid;
 };
 
 #endif // MAPENGINE_H