use std::path::PathBuf;
use std::time::Duration;
use cog_tiles::{AsyncIndexedMosaic, HrefResolver, IndexedMosaicOptions, TileIndex};
use crate::CacheZoomRange;
use crate::tiles::cog::CogError;
use crate::tiles::cog::source::CogSource;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CogTileIndexOptions {
pub path: PathBuf,
pub layer: Option<String>,
pub location_field: String,
pub min_zoom: u8,
pub max_zoom: Option<u8>,
pub bands: Vec<usize>,
pub nodata: Option<u8>,
pub max_cached_files: u64,
pub file_expiry: Duration,
pub file_idle_timeout: Option<Duration>,
}
impl CogSource {
pub async fn new_tile_index(
id: String,
options: CogTileIndexOptions,
resolve: &HrefResolver,
cache_zoom: CacheZoomRange,
) -> Result<Self, CogError> {
let index = TileIndex::open(
&options.path,
options.layer.as_deref(),
&options.location_field,
resolve,
)
.await?;
let mosaic_options = IndexedMosaicOptions::new(options.min_zoom, options.bands)
.with_max_zoom(options.max_zoom)
.with_nodata(options.nodata)
.with_max_cached_files(options.max_cached_files)
.with_file_expiry(options.file_expiry)
.with_file_idle_timeout(options.file_idle_timeout);
let mosaic = AsyncIndexedMosaic::open_tile_index(index, mosaic_options).await?;
Self::from_indexed(id, mosaic, options.path.display().to_string(), cache_zoom)
}
}