Skip to main content

mln_style/layers/
heatmap_layer_properties.rs

1// This file is generated by //tools/style-codegen from the style spec
2// (tools/style-codegen/v8.json). Do not edit.
3
4use crate::conversion::{Convertible, Error};
5use crate::expression::Functions;
6use crate::layer::LayerStyle;
7use crate::layers::Heatmap;
8use crate::property::color_ramp::{ColorRampPropertyValue, convert_color_ramp_property_value};
9use crate::property::table::{PropertyInfo, PropertyTable, PropertyVisitor};
10
11crate::properties!(
12    /// The paint properties of a heatmap layer.
13    #[expect(non_snake_case, reason = "named as a type: the module stands for the layer's set of properties")]
14    pub mod HeatmapPaintProperties: paint {
15        heatmap_color: color_ramp Color = Color::default(),
16        heatmap_intensity: constant f32 = 1.0_f32,
17        heatmap_opacity: constant f32 = 1.0_f32,
18        heatmap_radius: data_driven f32 = 30.0_f32,
19        heatmap_weight: data_driven f32 = 1.0_f32,
20    }
21    use crate::color::Color;
22);
23
24/// The properties, by slot.
25pub(crate) static PROPERTIES: PropertyTable = PropertyTable::new(
26    &[
27        PropertyInfo::paint("heatmap-color").interpolated(),
28        PropertyInfo::paint("heatmap-intensity").interpolated(),
29        PropertyInfo::paint("heatmap-opacity").interpolated(),
30        PropertyInfo::paint("heatmap-radius").data_driven().interpolated(),
31        PropertyInfo::paint("heatmap-weight").data_driven().interpolated(),
32    ],
33    &[0, 1, 2, 3, 4],
34);
35
36/// Calls `visitor` with the field of the property in `slot`.
37pub(crate) fn visit<V: PropertyVisitor<LayerStyle<Heatmap>>>(slot: usize, visitor: V) -> Option<V::Output> {
38    Some(match slot {
39        0 => visitor.paint(|s| &s.paint.heatmap_color, |s| &mut s.paint.heatmap_color),
40        1 => visitor.paint(|s| &s.paint.heatmap_intensity, |s| &mut s.paint.heatmap_intensity),
41        2 => visitor.paint(|s| &s.paint.heatmap_opacity, |s| &mut s.paint.heatmap_opacity),
42        3 => visitor.paint(|s| &s.paint.heatmap_radius, |s| &mut s.paint.heatmap_radius),
43        4 => visitor.paint(|s| &s.paint.heatmap_weight, |s| &mut s.paint.heatmap_weight),
44        _ => return None,
45    })
46}
47
48/// The default `heatmap-color`.
49#[must_use]
50pub fn default_heatmap_color() -> ColorRampPropertyValue {
51    let mut error = Error::default();
52    let raw_value = serde_json::json!([
53        "interpolate",
54        ["linear"],
55        ["heatmap-density"],
56        0,
57        "rgba(0, 0, 255, 0)",
58        0.1,
59        "royalblue",
60        0.3,
61        "cyan",
62        0.5,
63        "lime",
64        0.7,
65        "yellow",
66        1,
67        "red"
68    ]);
69    #[expect(clippy::expect_used, reason = "the generated style-spec default always converts")]
70    convert_color_ramp_property_value(&Convertible::from(&raw_value), &mut error, &Functions::with_builtins())
71        .expect("the heatmap-color default converts")
72}