Skip to main content

mln_style/layers/
fill_layer.rs

1use crate::layer::{LayerStyle, LayerTypeInfo, SourceKind, StyleLayerType};
2use crate::layers::fill_layer_properties::{self, FillLayoutProperties, FillPaintProperties};
3use crate::property::table::{PropertyTable, PropertyVisitor};
4use crate::property::value::PropertyValue;
5use crate::types::LayerBlendType;
6
7/// The `fill` layer type.
8pub struct Fill;
9
10impl StyleLayerType for Fill {
11    const INFO: LayerTypeInfo = LayerTypeInfo { name: "fill", source: SourceKind::Geometry, from_json: true };
12    const PROPERTIES: &'static PropertyTable = &fill_layer_properties::PROPERTIES;
13
14    type LayoutProperties = FillLayoutProperties::Unevaluated;
15    type PaintProperties = FillPaintProperties::Transitionable;
16    type Extra = ();
17
18    fn visit_property<V: PropertyVisitor<LayerStyle<Self>>>(slot: usize, visitor: V) -> Option<V::Output> {
19        fill_layer_properties::visit(slot, visitor)
20    }
21
22    /// Fills round their corners only in tiles laid out to, so turning
23    /// `fill-rounded-corner-distance` on lays them out again. Turning it off
24    /// doesn't: rounded tiles draw sharp corners at 0, and a transition
25    /// down to 0 moves along their arcs.
26    fn paint_lays_out(before: &LayerStyle<Self>, after: &LayerStyle<Self>) -> bool {
27        !rounds_corners(before) && rounds_corners(after)
28    }
29
30    fn layer_blend(paint: &FillPaintProperties::PossiblyEvaluated) -> LayerBlendType {
31        *paint.fill_layer_blend.uniform()
32    }
33}
34
35/// Whether a fill layer may round its polygons' corners: whether its
36/// `fill-rounded-corner-distance` is anything but undefined or 0.
37#[must_use]
38pub fn rounds_corners(style: &LayerStyle<Fill>) -> bool {
39    match &style.paint.fill_rounded_corner_distance.value {
40        PropertyValue::Undefined => false,
41        PropertyValue::Constant(distance) => *distance > 0.0,
42        PropertyValue::Expression(_) => true,
43    }
44}