use std::collections::BTreeMap;
pub mod camera;
pub mod expression;
pub mod mvt;
pub mod render;
pub mod sample;
pub mod source;
pub mod style;
pub mod symbol;
mod view;
pub use camera::{Camera, LngLat};
pub use render::FeatureHit;
pub use source::TileId;
pub use view::{MapStatus, MapTap, MapView, Marker, MarkerId, map, map_with_client};
#[derive(Clone, Debug, PartialEq)]
pub enum Value {
Null,
Bool(bool),
Number(f64),
String(String),
Color(day_geometry::Color),
Array(Vec<Value>),
Object(BTreeMap<String, Value>),
Formatted(Vec<FormattedSection>),
Image {
name: String,
available: bool,
},
Collator {
case_sensitive: bool,
diacritic_sensitive: bool,
locale: Option<String>,
},
}
#[derive(Clone, Debug, PartialEq)]
pub struct FormattedSection {
pub text: String,
pub image: Option<String>,
pub scale: Option<f64>,
pub font_stack: Option<Vec<String>>,
pub text_color: Option<day_geometry::Color>,
pub vertical_align: Option<String>,
}
impl Value {
pub fn as_f64(&self) -> Option<f64> {
match self {
Value::Number(n) => Some(*n),
_ => None,
}
}
pub fn as_str(&self) -> Option<&str> {
match self {
Value::String(s) => Some(s),
_ => None,
}
}
pub fn as_bool(&self) -> Option<bool> {
match self {
Value::Bool(b) => Some(*b),
_ => None,
}
}
pub fn as_color(&self) -> Option<day_geometry::Color> {
match self {
Value::Color(c) => Some(*c),
_ => None,
}
}
pub fn from_json(json: &serde_json::Value) -> Value {
match json {
serde_json::Value::Null => Value::Null,
serde_json::Value::Bool(b) => Value::Bool(*b),
serde_json::Value::Number(n) => Value::Number(n.as_f64().unwrap_or(f64::NAN)),
serde_json::Value::String(s) => Value::String(s.clone()),
serde_json::Value::Array(items) => {
Value::Array(items.iter().map(Value::from_json).collect())
}
serde_json::Value::Object(map) => Value::Object(
map.iter()
.map(|(k, v)| (k.clone(), Value::from_json(v)))
.collect(),
),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum GeometryType {
Unknown,
Point,
LineString,
Polygon,
}
impl GeometryType {
pub fn name(self) -> &'static str {
match self {
GeometryType::Unknown => "Unknown",
GeometryType::Point => "Point",
GeometryType::LineString => "LineString",
GeometryType::Polygon => "Polygon",
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Feature {
pub id: Option<Value>,
pub kind: GeometryType,
pub properties: BTreeMap<String, Value>,
pub geometry: Vec<Vec<day_geometry::Point>>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum Error {
Invalid(String),
Http(String),
Status { url: String, status: u16 },
Unsupported(String),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Invalid(why) => write!(f, "invalid: {why}"),
Error::Http(why) => write!(f, "request failed: {why}"),
Error::Status { url, status } => write!(f, "{url} answered {status}"),
Error::Unsupported(what) => write!(f, "unsupported: {what}"),
}
}
}
impl std::error::Error for Error {}