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) {
|
||||
indeces << index;
|
||||
void collectDownloadIndeces(OSMTileCache * cache, QQueue<OSM::TileIndex> & 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<OSM::TileIndex> 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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user