use plotly_derive::FieldSetter;
use serde::Serialize;
use crate::common::Domain;
#[derive(Serialize, Clone, Debug)]
pub struct Center {
lat: f64,
lon: f64,
}
impl Center {
pub fn new(lat: f64, lon: f64) -> Self {
Center { lat, lon }
}
}
#[derive(Serialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
pub enum MapboxStyle {
#[serde(rename = "carto-darkmatter")]
CartoDarkMatter,
CartoPositron,
OpenStreetMap,
StamenTerrain,
StamenToner,
StamenWatercolor,
WhiteBg,
Basic,
Streets,
Outdoors,
Light,
Dark,
Satellite,
SatelliteStreets,
}
#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug, FieldSetter)]
pub struct Mapbox {
#[serde(rename = "accesstoken")]
access_token: Option<String>,
bearing: Option<f64>,
center: Option<Center>,
domain: Option<Domain>,
pitch: Option<f64>,
style: Option<MapboxStyle>,
zoom: Option<u8>,
}
impl Mapbox {
pub fn new() -> Self {
Default::default()
}
}
#[cfg(test)]
mod tests {
use serde_json::{json, to_value};
use super::*;
#[test]
#[rustfmt::skip]
fn serialize_mapbox_style() {
assert_eq!(to_value(MapboxStyle::CartoDarkMatter).unwrap(), json!("carto-darkmatter"));
assert_eq!(to_value(MapboxStyle::CartoPositron).unwrap(), json!("carto-positron"));
assert_eq!(to_value(MapboxStyle::OpenStreetMap).unwrap(), json!("open-street-map"));
assert_eq!(to_value(MapboxStyle::StamenTerrain).unwrap(), json!("stamen-terrain"));
assert_eq!(to_value(MapboxStyle::StamenToner).unwrap(), json!("stamen-toner"));
assert_eq!(to_value(MapboxStyle::StamenWatercolor).unwrap(), json!("stamen-watercolor"));
assert_eq!(to_value(MapboxStyle::WhiteBg).unwrap(), json!("white-bg"));
assert_eq!(to_value(MapboxStyle::Basic).unwrap(), json!("basic"));
assert_eq!(to_value(MapboxStyle::Streets).unwrap(), json!("streets"));
assert_eq!(to_value(MapboxStyle::Outdoors).unwrap(), json!("outdoors"));
assert_eq!(to_value(MapboxStyle::Light).unwrap(), json!("light"));
assert_eq!(to_value(MapboxStyle::Dark).unwrap(), json!("dark"));
assert_eq!(to_value(MapboxStyle::Satellite).unwrap(), json!("satellite"));
assert_eq!(to_value(MapboxStyle::SatelliteStreets).unwrap(), json!("satellite-streets"));
}
}