Skip to main content

mln_style/layers/
fill_extrusion_layer.rs

1use crate::collections::VecSet;
2use crate::expression::Dependency;
3use crate::layer::{LayerStyle, LayerTypeInfo, SourceKind, StyleLayerType};
4use crate::layers::fill_extrusion_layer_properties::{
5    self, FillExtrusionLayoutProperties, FillExtrusionPaintProperties,
6};
7use crate::property::table::{PropertyTable, PropertyVisitor};
8use crate::property::value::StyleValue as _;
9
10/// The `fill-extrusion` layer type.
11pub struct FillExtrusion;
12
13impl StyleLayerType for FillExtrusion {
14    const INFO: LayerTypeInfo = LayerTypeInfo { name: "fill-extrusion", source: SourceKind::Geometry, from_json: true };
15    const PROPERTIES: &'static PropertyTable = &fill_extrusion_layer_properties::PROPERTIES;
16
17    type LayoutProperties = FillExtrusionLayoutProperties::Unevaluated;
18    type PaintProperties = FillExtrusionPaintProperties::Transitionable;
19    type Extra = ();
20
21    fn visit_property<V: PropertyVisitor<LayerStyle<Self>>>(slot: usize, visitor: V) -> Option<V::Output> {
22        fill_extrusion_layer_properties::visit(slot, visitor)
23    }
24
25    /// A color by `["elevation"]` is laid out up to each extrusion's height,
26    /// so a change of the height lays it out again.
27    fn paint_lays_out(a: &LayerStyle<Self>, b: &LayerStyle<Self>) -> bool {
28        let by_elevation = |style: &LayerStyle<Self>| {
29            style.paint.fill_extrusion_color.value.dependencies().intersects(Dependency::ELEVATION)
30        };
31        (by_elevation(a) || by_elevation(b))
32            && a.paint.fill_extrusion_height.value != b.paint.fill_extrusion_height.value
33    }
34
35    /// The height's, which a color by `["elevation"]` is laid out up to.
36    fn paint_layout_global_state_refs(style: &LayerStyle<Self>) -> Option<&VecSet<String>> {
37        let by_elevation = style.paint.fill_extrusion_color.value.dependencies().intersects(Dependency::ELEVATION);
38        by_elevation.then(|| style.paint.fill_extrusion_height.value.global_state_refs()).flatten()
39    }
40
41    /// The height's host-dependent functions, when color reads `["elevation"]`.
42    fn paint_layout_host_function_refs(style: &LayerStyle<Self>) -> Option<&VecSet<String>> {
43        let by_elevation = style.paint.fill_extrusion_color.value.dependencies().intersects(Dependency::ELEVATION);
44        by_elevation.then(|| style.paint.fill_extrusion_height.value.host_function_refs()).flatten()
45    }
46}