mln-rs-style 0.0.21

Part of mln-rs, a MapLibre map renderer written in Rust. Depend on mln-rs instead.
Documentation
// This file is generated by //tools/style-codegen from the style spec
// (tools/style-codegen/v8.json). Do not edit.

use crate::conversion::{Convertible, Error};
use crate::expression::Functions;
use crate::layer::LayerStyle;
use crate::layers::Heatmap;
use crate::property::color_ramp::{ColorRampPropertyValue, convert_color_ramp_property_value};
use crate::property::table::{PropertyInfo, PropertyTable, PropertyVisitor};

crate::properties!(
    /// The paint properties of a heatmap layer.
    #[expect(non_snake_case, reason = "named as a type: the module stands for the layer's set of properties")]
    pub mod HeatmapPaintProperties: paint {
        heatmap_color: color_ramp Color = Color::default(),
        heatmap_intensity: constant f32 = 1.0_f32,
        heatmap_opacity: constant f32 = 1.0_f32,
        heatmap_radius: data_driven f32 = 30.0_f32,
        heatmap_weight: data_driven f32 = 1.0_f32,
    }
    use crate::color::Color;
);

/// The properties, by slot.
pub(crate) static PROPERTIES: PropertyTable = PropertyTable::new(
    &[
        PropertyInfo::paint("heatmap-color"),
        PropertyInfo::paint("heatmap-intensity"),
        PropertyInfo::paint("heatmap-opacity"),
        PropertyInfo::paint("heatmap-radius").data_driven(),
        PropertyInfo::paint("heatmap-weight").data_driven(),
    ],
    &[0, 1, 2, 3, 4],
);

/// Calls `visitor` with the field of the property in `slot`.
pub(crate) fn visit<V: PropertyVisitor<LayerStyle<Heatmap>>>(slot: usize, visitor: V) -> Option<V::Output> {
    Some(match slot {
        0 => visitor.paint(|s| &s.paint.heatmap_color, |s| &mut s.paint.heatmap_color),
        1 => visitor.paint(|s| &s.paint.heatmap_intensity, |s| &mut s.paint.heatmap_intensity),
        2 => visitor.paint(|s| &s.paint.heatmap_opacity, |s| &mut s.paint.heatmap_opacity),
        3 => visitor.paint(|s| &s.paint.heatmap_radius, |s| &mut s.paint.heatmap_radius),
        4 => visitor.paint(|s| &s.paint.heatmap_weight, |s| &mut s.paint.heatmap_weight),
        _ => return None,
    })
}

/// The default `heatmap-color`.
#[must_use]
pub fn default_heatmap_color() -> ColorRampPropertyValue {
    let mut error = Error::default();
    let raw_value = serde_json::json!([
        "interpolate",
        ["linear"],
        ["heatmap-density"],
        0,
        "rgba(0, 0, 255, 0)",
        0.1,
        "royalblue",
        0.3,
        "cyan",
        0.5,
        "lime",
        0.7,
        "yellow",
        1,
        "red"
    ]);
    convert_color_ramp_property_value(&Convertible::from(&raw_value), &mut error, &Functions::with_builtins())
        .expect("the heatmap-color default converts")
}