pub trait Layer: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn visible(&self) -> bool;
fn set_visible(&mut self, visible: bool);
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
// Provided methods
fn id(&self) -> LayerId { ... }
fn kind(&self) -> LayerKind { ... }
fn opacity(&self) -> f32 { ... }
fn set_opacity(&mut self, _opacity: f32) { ... }
fn z_index(&self) -> i32 { ... }
}Expand description
A named, renderable layer in the map scene.
Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
Human-readable name for UI and debug output.
Names are not required to be unique. Use id()
when you need a stable, unique key.
Sourcefn visible(&self) -> bool
fn visible(&self) -> bool
Whether this layer participates in the current frame.
Invisible layers are skipped entirely during the update loop (no tile fetches, no tessellation, no draw calls).
Sourcefn set_visible(&mut self, visible: bool)
fn set_visible(&mut self, visible: bool)
Toggle visibility on or off.
Sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Borrow the layer as &dyn Any for concrete type access.
This enables safe downcasting in the engine update loop and in renderer-specific code:
if let Some(tile_layer) = layer.as_any().downcast_ref::<TileLayer>() {
// ...
}Sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Borrow the layer as &mut dyn Any for mutable concrete type access.
Provided Methods§
Sourcefn id(&self) -> LayerId
fn id(&self) -> LayerId
A process-unique identifier for this layer.
Override this to return the LayerId you stored at construction
time. The default implementation allocates a new id on every
call, which is correct for one-shot queries but wasteful if
called repeatedly – concrete types should store the id instead.
Sourcefn kind(&self) -> LayerKind
fn kind(&self) -> LayerKind
The concrete layer type for enum-based dispatch.
The engine’s update loop uses this to avoid trial-and-error
downcasting. Built-in types (TileLayer,
HillshadeLayer,
VectorLayer,
ModelLayer) return their
corresponding LayerKind variant. Custom types default to
LayerKind::Custom.
Sourcefn opacity(&self) -> f32
fn opacity(&self) -> f32
Layer opacity in the range [0.0, 1.0].
Renderers should multiply the per-fragment alpha by this value.
The default is fully opaque (1.0).
Sourcefn set_opacity(&mut self, _opacity: f32)
fn set_opacity(&mut self, _opacity: f32)
Set the layer opacity.
Implementations must clamp the value to [0.0, 1.0].
The default implementation is a no-op – override it if the
concrete type stores opacity.
Sourcefn z_index(&self) -> i32
fn z_index(&self) -> i32
Hint for render ordering within the layer stack.
Lower values are drawn first (further from the viewer). The
engine uses the stack position as the primary sort key; z_index
acts as a secondary key for layers that want to override their
natural stack position without being physically reordered.
The default is 0 (no override).