TileLoader::TileLoader(const std::string &service, double latitude, double longitude, unsigned int zoom, unsigned int blocks, QObject *parent) : QObject(parent), latitude_(latitude), longitude_(longitude), zoom_(zoom), blocks_(blocks), object_uri_(service) { assert(blocks_ >= 0); const std::string package_path = ros::package::getPath("rviz_satellite"); if (package_path.empty()) { throw std::runtime_error("package 'rviz_satellite' not found"); } std::hash<std::string> hash_fn; cache_path_ = QDir::cleanPath(QString::fromStdString(package_path) + QDir::separator() + QString("mapscache") + QDir::separator() + QString::number(hash_fn(object_uri_))); QDir dir(cache_path_); if (!dir.exists() && !dir.mkpath(".")) { throw std::runtime_error("Failed to create cache folder: " + cache_path_.toStdString()); } /// @todo: some kind of error checking of the URL // calculate center tile coordinates double x, y; latLonToTileCoords(latitude_, longitude_, zoom_, x, y); center_tile_x_ = std::floor(x); center_tile_y_ = std::floor(y); // fractional component origin_offset_x_ = x - center_tile_x_; origin_offset_y_ = y - center_tile_y_; }
TileLoader::TileLoader(const std::string &service, double latitude, double longitude, unsigned int zoom, unsigned int blocks, QObject *parent) : QObject(parent), latitude_(latitude), longitude_(longitude), zoom_(zoom), blocks_(blocks), qnam_(0), object_uri_(service) { assert(blocks_ >= 0); /// @todo: some kind of error checking of the URL // calculate center tile coordinates double x, y; latLonToTileCoords(latitude_, longitude_, zoom_, x, y); tile_x_ = std::floor(x); tile_y_ = std::floor(y); // fractional component origin_x_ = x - tile_x_; origin_y_ = y - tile_y_; }
bool TileLoader::insideCentreTile(double lat, double lon) const { double x, y; latLonToTileCoords(lat, lon, zoom_, x, y); return (std::floor(x) == center_tile_x_ && std::floor(y) == center_tile_y_); }