use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[must_use]
pub struct LayerOptions {
pub id: String,
#[serde(rename = "type")]
pub layer_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub source: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_layer: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub paint: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub layout: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub filter: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub min_zoom: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_zoom: Option<f64>,
}
impl LayerOptions {
pub fn new(
id: impl Into<String>,
layer_type: impl Into<String>,
source: impl Into<String>,
) -> Self {
Self {
id: id.into(),
layer_type: layer_type.into(),
source: Some(source.into()),
source_layer: None,
paint: None,
layout: None,
filter: None,
min_zoom: None,
max_zoom: None,
}
}
pub fn circle(id: impl Into<String>, source: impl Into<String>) -> Self {
Self::new(id, "circle", source)
}
pub fn fill(id: impl Into<String>, source: impl Into<String>) -> Self {
Self::new(id, "fill", source)
}
pub fn line(id: impl Into<String>, source: impl Into<String>) -> Self {
Self::new(id, "line", source)
}
pub fn symbol(id: impl Into<String>, source: impl Into<String>) -> Self {
Self::new(id, "symbol", source)
}
pub fn fill_extrusion(id: impl Into<String>, source: impl Into<String>) -> Self {
Self::new(id, "fill-extrusion", source)
}
pub fn heatmap(id: impl Into<String>, source: impl Into<String>) -> Self {
Self::new(id, "heatmap", source)
}
pub fn raster(id: impl Into<String>, source: impl Into<String>) -> Self {
Self::new(id, "raster", source)
}
pub fn background(id: impl Into<String>) -> Self {
Self {
id: id.into(),
layer_type: "background".into(),
source: None,
source_layer: None,
paint: None,
layout: None,
filter: None,
min_zoom: None,
max_zoom: None,
}
}
pub fn source_layer(mut self, layer: impl Into<String>) -> Self {
self.source_layer = Some(layer.into());
self
}
pub fn paint(mut self, paint: serde_json::Value) -> Self {
self.paint = Some(paint);
self
}
pub fn layout(mut self, layout: serde_json::Value) -> Self {
self.layout = Some(layout);
self
}
pub fn filter(mut self, filter: serde_json::Value) -> Self {
self.filter = Some(filter);
self
}
pub fn min_zoom(mut self, zoom: f64) -> Self {
self.min_zoom = Some(zoom);
self
}
pub fn max_zoom(mut self, zoom: f64) -> Self {
self.max_zoom = Some(zoom);
self
}
}