use crate::TileId;
use super::{Attribution, TileSource};
#[derive(Clone, Copy, Default)]
pub enum MapboxStyle {
#[default]
Streets,
Outdoors,
Light,
Dark,
Satellite,
SatelliteStreets,
NavigationDay,
NavigationNight,
}
impl MapboxStyle {
fn api_slug(&self) -> &'static str {
match self {
Self::Streets => "streets-v12",
Self::Outdoors => "outdoors-v12",
Self::Light => "light-v11",
Self::Dark => "dark-v11",
Self::Satellite => "satellite-v9",
Self::SatelliteStreets => "satellite-streets-v12",
Self::NavigationDay => "navigation-day-v1",
Self::NavigationNight => "navigation-night-v1",
}
}
}
#[derive(Default)]
pub struct Mapbox {
pub style: MapboxStyle,
pub high_resolution: bool,
pub access_token: String,
}
impl TileSource for Mapbox {
fn tile_url(&self, tile_id: TileId) -> String {
format!(
"https://api.mapbox.com/styles/v1/mapbox/{}/tiles/512/{}/{}/{}{}?access_token={}",
self.style.api_slug(),
tile_id.zoom,
tile_id.x,
tile_id.y,
if self.high_resolution { "@2x" } else { "" },
self.access_token
)
}
fn attribution(&self) -> Attribution {
Attribution {
text: "© Mapbox, © OpenStreetMap",
url: "https://www.mapbox.com/about/maps/",
logo_light: Some(egui::include_image!("../../assets/mapbox-logo-white.svg")),
logo_dark: Some(egui::include_image!("../../assets/mapbox-logo-black.svg")),
}
}
fn tile_size(&self) -> u32 {
512
}
}