void TileLoader::start() { // discard previous set of tiles and all pending requests abort(); qnam_ = new QNetworkAccessManager(this); QObject::connect(qnam_, SIGNAL(finished(QNetworkReply *)), this, SLOT(finishedRequest(QNetworkReply *))); // determine what range of tiles we can load const int min_x = std::max(0, tile_x_ - blocks_); const int min_y = std::max(0, tile_y_ - blocks_); const int max_x = std::min(maxTiles(), tile_x_ + blocks_); const int max_y = std::min(maxTiles(), tile_y_ + blocks_); // initiate requests for (int y = min_y; y <= max_y; y++) { for (int x = min_x; x <= max_x; x++) { const QUrl uri = uriForTile(x, y); // send request const QNetworkRequest request = QNetworkRequest(uri); QNetworkReply *rep = qnam_->get(request); emit initiatedRequest(request); tiles_.push_back(MapTile(x, y, rep)); } } }
void TileLoader::start() { // discard previous set of tiles and all pending requests abort(); ROS_INFO("loading %d blocks around tile=(%d,%d)", blocks_, center_tile_x_, center_tile_y_ ); qnam_.reset( new QNetworkAccessManager(this) ); QObject::connect(qnam_.get(), SIGNAL(finished(QNetworkReply *)), this, SLOT(finishedRequest(QNetworkReply *))); // determine what range of tiles we can load const int min_x = std::max(0, center_tile_x_ - blocks_); const int min_y = std::max(0, center_tile_y_ - blocks_); const int max_x = std::min(maxTiles(), center_tile_x_ + blocks_); const int max_y = std::min(maxTiles(), center_tile_y_ + blocks_); // initiate requests for (int y = min_y; y <= max_y; y++) { for (int x = min_x; x <= max_x; x++) { // Generate filename const QString full_path = cachedPathForTile(x, y, zoom_); // Check if tile is already in the cache QFile tile(full_path); if (tile.exists()) { QImage image(full_path); tiles_.push_back(MapTile(x, y, zoom_, image)); } else { const QUrl uri = uriForTile(x, y, zoom_); // send request const QNetworkRequest request = QNetworkRequest(uri); QNetworkReply *rep = qnam_->get(request); emit initiatedRequest(request); tiles_.push_back(MapTile(x, y, zoom_, rep)); } } } checkIfLoadingComplete(); }