diff --git a/libs/map/mapview.cpp b/libs/map/mapview.cpp index ab250d8..318e39a 100644 --- a/libs/map/mapview.cpp +++ b/libs/map/mapview.cpp @@ -92,21 +92,25 @@ void MapView::setCachePath(const QString & p) { } -void collectDownloadIndeces(QQueue & indeces, OSM::TileIndex index, int target_zoom_level) { - indeces << index; +void collectDownloadIndeces(OSMTileCache * cache, QQueue & indeces, OSM::TileIndex index, int target_zoom_level, bool only_new) { + if (only_new) { + if (!cache->isTileFileExists(index)) + indeces << index; + } else + indeces << index; if (index.z >= target_zoom_level) return; int z = index.z + 1; int x = index.x * 2; int y = index.y * 2; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { - collectDownloadIndeces(indeces, (OSM::TileIndex){z, x + i, y + j}, target_zoom_level); + collectDownloadIndeces(cache, indeces, (OSM::TileIndex){z, x + i, y + j}, target_zoom_level, only_new); } } } -void MapView::downloadCurrentView(int target_zoom_level) { +void MapView::downloadCurrentView(int target_zoom_level, bool only_new) { int sx = qMax(0, (int)floor(view_rect.left() * tiles_side)); int sy = qMax(0, (int)floor(view_rect.top() * tiles_side)); int ex = qMin(tiles_side, (int)ceil(view_rect.right() * tiles_side)); @@ -115,7 +119,7 @@ void MapView::downloadCurrentView(int target_zoom_level) { QQueue indeces; for (int ix = sx; ix < ex; ++ix) { for (int iy = sy; iy < ey; ++iy) { - collectDownloadIndeces(indeces, (OSM::TileIndex){zoom_level, ix, iy}, target_zoom_level); + collectDownloadIndeces(cache, indeces, (OSM::TileIndex){zoom_level, ix, iy}, target_zoom_level, only_new); } } if (indeces.size() < 4) return; @@ -166,6 +170,7 @@ void MapView::downloadCurrentView(int target_zoom_level) { void MapView::mousePressEvent(QMouseEvent * e) { is_pan = false; press_point = e->pos(); + zoom_anchor = press_point; last_click_coord = OSM::xy2geo(mapToNorm(press_point)); } @@ -199,6 +204,11 @@ void MapView::mouseMoveEvent(QMouseEvent * e) { if ((e->pos() - press_point).manhattanLength() >= QApplication::startDragDistance()) is_pan = true; } } + if (e->buttons() == Qt::RightButton) { + auto dp = e->pos() - press_point; + press_point = e->pos(); + zoom(1. - dp.y() / 50., zoom_anchor); + } updateMouse(e->pos()); } diff --git a/libs/map/mapview.h b/libs/map/mapview.h index 33888a5..a417102 100644 --- a/libs/map/mapview.h +++ b/libs/map/mapview.h @@ -61,7 +61,7 @@ public: QString cachePath() const; void setCachePath(const QString & p); - void downloadCurrentView(int target_zoom_level = 17); + void downloadCurrentView(int target_zoom_level = 17, bool only_new = true); protected: QSize sizeHint() const override { return QSize(200, 200); } @@ -92,7 +92,7 @@ private: MapItemBase * hover = nullptr; QPointF center_ = QPointF(0.5, 0.5); QPointF last_click_coord = center_; - QPoint press_point; + QPoint press_point, zoom_anchor; QPixmap background; QRectF view_rect; QVector items_; diff --git a/libs/map/osm_tile_cache.cpp b/libs/map/osm_tile_cache.cpp index 8252c14..ec9a66b 100644 --- a/libs/map/osm_tile_cache.cpp +++ b/libs/map/osm_tile_cache.cpp @@ -54,6 +54,14 @@ OSM::TilePixmap OSMTileCache::getTile(OSM::TileIndex index, QRectF & rect_src) { } +bool OSMTileCache::isTileFileExists(OSM::TileIndex index) const { + QString hashdir = index.cacheDir(); + if (!cache_dir.exists(hashdir)) return false; + QString hashname = hashdir + "/" + index.hashName(); + return cache_dir.exists(hashname); +} + + void OSMTileCache::setCacheRoot(const QString & p) { cache_root = p; cache_dir.setPath(cache_root); diff --git a/libs/map/osm_tile_cache_p.h b/libs/map/osm_tile_cache_p.h index a008a31..8b0a731 100644 --- a/libs/map/osm_tile_cache_p.h +++ b/libs/map/osm_tile_cache_p.h @@ -50,6 +50,8 @@ public: void tileDownloaded(OSM::TileIndex index, const QPixmap & pixmap); OSM::TilePixmap getTile(OSM::TileIndex index, QRectF & rect_src); + bool isTileFileExists(OSM::TileIndex index) const; + QString cacheRoot() const { return cache_root; } void setCacheRoot(const QString & p);