use tiles_client::Client;
use crate::{Feature, ImageData, ImageFeature, Layer, Projection};
pub struct Tile(tiles_client::Tile);
impl ImageData for Tile
{
fn bounding_box(&self) -> geo::Rect
{
self.0.bounding_box()
}
fn pixel_size(&self) -> (u32, u32)
{
self.0.pixel_size()
}
fn rgba_data(&self) -> Vec<u8>
{
self.0.rgba_data()
}
}
pub struct TilesLayer
{
projection: Projection,
client: tiles_client::Client,
}
impl TilesLayer
{
pub fn new(client: Client) -> Self
{
Self {
client,
projection: Projection::wgs84(),
}
}
}
impl<TFeature> Layer<TFeature> for TilesLayer
where
TFeature: Feature + From<ImageFeature<Tile>>,
{
fn projection(&self) -> &crate::Projection
{
&self.projection
}
fn features<'a>(
&'a self,
rect: geo::Rect,
zoom_level: f64,
) -> Box<dyn Iterator<Item = crate::RefOrValue<'a, TFeature>> + 'a>
{
Box::new(
self
.client
.tiles(rect, zoom_level.ceil() as u32, true)
.into_iter()
.map(|x| {
let tile: ImageFeature<Tile> = Tile(x).into();
let tile: TFeature = tile.into();
tile.into()
}),
)
}
}