download
This commit is contained in:
@@ -92,21 +92,25 @@ void MapView::setCachePath(const QString & p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void collectDownloadIndeces(QQueue<OSM::TileIndex> & indeces, OSM::TileIndex index, int target_zoom_level) {
|
void collectDownloadIndeces(OSMTileCache * cache, QQueue<OSM::TileIndex> & indeces, OSM::TileIndex index, int target_zoom_level, bool only_new) {
|
||||||
indeces << index;
|
if (only_new) {
|
||||||
|
if (!cache->isTileFileExists(index))
|
||||||
|
indeces << index;
|
||||||
|
} else
|
||||||
|
indeces << index;
|
||||||
if (index.z >= target_zoom_level) return;
|
if (index.z >= target_zoom_level) return;
|
||||||
int z = index.z + 1;
|
int z = index.z + 1;
|
||||||
int x = index.x * 2;
|
int x = index.x * 2;
|
||||||
int y = index.y * 2;
|
int y = index.y * 2;
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
for (int j = 0; j < 2; ++j) {
|
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 sx = qMax(0, (int)floor(view_rect.left() * tiles_side));
|
||||||
int sy = qMax(0, (int)floor(view_rect.top() * 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));
|
int ex = qMin(tiles_side, (int)ceil(view_rect.right() * tiles_side));
|
||||||
@@ -115,7 +119,7 @@ void MapView::downloadCurrentView(int target_zoom_level) {
|
|||||||
QQueue<OSM::TileIndex> indeces;
|
QQueue<OSM::TileIndex> indeces;
|
||||||
for (int ix = sx; ix < ex; ++ix) {
|
for (int ix = sx; ix < ex; ++ix) {
|
||||||
for (int iy = sy; iy < ey; ++iy) {
|
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;
|
if (indeces.size() < 4) return;
|
||||||
@@ -166,6 +170,7 @@ void MapView::downloadCurrentView(int target_zoom_level) {
|
|||||||
void MapView::mousePressEvent(QMouseEvent * e) {
|
void MapView::mousePressEvent(QMouseEvent * e) {
|
||||||
is_pan = false;
|
is_pan = false;
|
||||||
press_point = e->pos();
|
press_point = e->pos();
|
||||||
|
zoom_anchor = press_point;
|
||||||
last_click_coord = OSM::xy2geo(mapToNorm(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->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());
|
updateMouse(e->pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
QString cachePath() const;
|
QString cachePath() const;
|
||||||
void setCachePath(const QString & p);
|
void setCachePath(const QString & p);
|
||||||
|
|
||||||
void downloadCurrentView(int target_zoom_level = 17);
|
void downloadCurrentView(int target_zoom_level = 17, bool only_new = true);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSize sizeHint() const override { return QSize(200, 200); }
|
QSize sizeHint() const override { return QSize(200, 200); }
|
||||||
@@ -92,7 +92,7 @@ private:
|
|||||||
MapItemBase * hover = nullptr;
|
MapItemBase * hover = nullptr;
|
||||||
QPointF center_ = QPointF(0.5, 0.5);
|
QPointF center_ = QPointF(0.5, 0.5);
|
||||||
QPointF last_click_coord = center_;
|
QPointF last_click_coord = center_;
|
||||||
QPoint press_point;
|
QPoint press_point, zoom_anchor;
|
||||||
QPixmap background;
|
QPixmap background;
|
||||||
QRectF view_rect;
|
QRectF view_rect;
|
||||||
QVector<MapItemBase *> items_;
|
QVector<MapItemBase *> items_;
|
||||||
|
|||||||
@@ -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) {
|
void OSMTileCache::setCacheRoot(const QString & p) {
|
||||||
cache_root = p;
|
cache_root = p;
|
||||||
cache_dir.setPath(cache_root);
|
cache_dir.setPath(cache_root);
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ public:
|
|||||||
void tileDownloaded(OSM::TileIndex index, const QPixmap & pixmap);
|
void tileDownloaded(OSM::TileIndex index, const QPixmap & pixmap);
|
||||||
OSM::TilePixmap getTile(OSM::TileIndex index, QRectF & rect_src);
|
OSM::TilePixmap getTile(OSM::TileIndex index, QRectF & rect_src);
|
||||||
|
|
||||||
|
bool isTileFileExists(OSM::TileIndex index) const;
|
||||||
|
|
||||||
QString cacheRoot() const { return cache_root; }
|
QString cacheRoot() const { return cache_root; }
|
||||||
void setCacheRoot(const QString & p);
|
void setCacheRoot(const QString & p);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user