void AerialMapDisplay::loadImagery() {
  if (loader_) {
    //  cancel current imagery, if any
    loader_->abort();
    delete loader_;
    loader_ = 0;
  }
  if (!received_msg_) {
    //  no message received from publisher
    return;
  }
  if (object_uri_.empty()) {
    setStatus(StatusProperty::Error, "Message",
              "Received message but object URI is not set");
  }
  const std::string service = object_uri_;
  try {
    loader_ = new TileLoader(service, ref_lat_, ref_lon_, zoom_, blocks_, this);
  }
  catch (std::exception &e) {
    setStatus(StatusProperty::Error, "Message", QString(e.what()));
    return;
  }

  QObject::connect(loader_, SIGNAL(errorOcurred(QString)), this,
                   SLOT(errorOcurred(QString)));
  QObject::connect(loader_, SIGNAL(finishedLoading()), this,
                   SLOT(finishedLoading()));
  QObject::connect(loader_, SIGNAL(initiatedRequest(QNetworkRequest)), this,
                   SLOT(initiatedRequest(QNetworkRequest)));
  QObject::connect(loader_, SIGNAL(receivedImage(QNetworkRequest)), this,
                   SLOT(receivedImage(QNetworkRequest)));
  //  start loading images
  loader_->start();
}
Example #2
0
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));
    }
  }
}
Example #3
0
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();
}