1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! PMTiles tile source.

use crate::datasource::{
    wms_fcgi::HttpRequestParams, LayerInfo, SourceType, TileResponse, TileSource, TileSourceError,
};
use crate::filter_params::FilterParams;
use crate::store::pmtiles::PmtilesStoreReader;
use crate::store::TileReader;
use async_trait::async_trait;
use bbox_core::Format;
use log::debug;
use tile_grid::{Tms, Xyz};
use tilejson::tilejson;
use tilejson::TileJSON;

#[async_trait]
impl TileSource for PmtilesStoreReader {
    async fn xyz_request(
        &self,
        _tms: &Tms,
        tile: &Xyz,
        _filter: &FilterParams,
        _format: &Format,
        _request_params: HttpRequestParams<'_>,
    ) -> Result<TileResponse, TileSourceError> {
        if let Some(tile) = self
            .get_tile(tile)
            .await
            .map_err(|_| TileSourceError::TileXyzError)?
        {
            Ok(tile)
        } else {
            Err(TileSourceError::TileXyzError) // TODO: check for empty tile?
        }
    }
    fn source_type(&self) -> SourceType {
        SourceType::Vector //TODO
    }
    async fn tilejson(&self, _tms: &Tms, format: &Format) -> Result<TileJSON, TileSourceError> {
        debug!(
            "Metadata {}: {}",
            self.path.display(),
            self.get_metadata().await?
        );
        let mut tj = tilejson! { tiles: vec![] };
        tj.other
            .insert("format".to_string(), format.file_suffix().into());
        Ok(tj)
    }
    async fn layers(&self) -> Result<Vec<LayerInfo>, TileSourceError> {
        Ok(vec![LayerInfo {
            name: self.path.to_string_lossy().to_string(), // TODO: file name only
            geometry_type: None,
            style: None,
        }])
    }
}