use crate::{coords::WorldTileCoords, style::source::TileAddressingScheme};
#[derive(Clone)]
pub struct TessellateSource {
pub url: String,
pub filetype: String,
}
impl TessellateSource {
pub fn new(url: &str, filetype: &str) -> Self {
Self {
url: url.to_string(),
filetype: filetype.to_string(),
}
}
pub fn format(&self, coords: &WorldTileCoords) -> String {
let tile_coords = coords.into_tile(TileAddressingScheme::XYZ).unwrap();
format!(
"{url}/{z}/{x}/{y}.{filetype}",
url = self.url,
z = tile_coords.z,
x = tile_coords.x,
y = tile_coords.y,
filetype = self.filetype,
)
}
}
impl Default for TessellateSource {
fn default() -> Self {
Self::new("https://maps.tuerantuer.org/europe_germany", "pbf")
}
}
#[derive(Clone)]
pub struct RasterSource {
pub url: String,
pub filetype: String,
pub key: String,
}
impl RasterSource {
pub fn new(url: &str, filetype: &str, key: &str) -> Self {
Self {
url: url.to_string(),
filetype: filetype.to_string(),
key: key.to_string(),
}
}
pub fn format(&self, coords: &WorldTileCoords) -> String {
let tile_coords = coords.into_tile(TileAddressingScheme::XYZ).unwrap();
format!(
"{url}/{z}/{x}/{y}.{filetype}?key={key}",
url = self.url,
z = tile_coords.z,
x = tile_coords.x,
y = tile_coords.y,
filetype = self.filetype,
key = self.key,
)
}
}
impl Default for RasterSource {
fn default() -> Self {
Self::new(
"https://api.maptiler.com/tiles/satellite-v2",
"jpg",
"qnePkfbGpMsLCi3KFBs3",
)
}
}
#[derive(Clone)]
pub enum SourceType {
Raster(RasterSource),
Tessellate(TessellateSource),
}
impl SourceType {
pub fn format(&self, coords: &WorldTileCoords) -> String {
match self {
SourceType::Raster(raster_source) => raster_source.format(coords),
SourceType::Tessellate(tessellate_source) => tessellate_source.format(coords),
}
}
}