mln_style/layers/
heatmap_layer_properties.rs1use 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 #[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
24pub(crate) static PROPERTIES: PropertyTable = PropertyTable::new(
26 &[
27 PropertyInfo::paint("heatmap-color"),
28 PropertyInfo::paint("heatmap-intensity"),
29 PropertyInfo::paint("heatmap-opacity"),
30 PropertyInfo::paint("heatmap-radius").data_driven(),
31 PropertyInfo::paint("heatmap-weight").data_driven(),
32 ],
33 &[0, 1, 2, 3, 4],
34);
35
36pub(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#[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 convert_color_ramp_property_value(&Convertible::from(&raw_value), &mut error, &Functions::with_builtins())
70 .expect("the heatmap-color default converts")
71}