Layer
Abstract base class for any layer that can be added to a viewport.
A layer owns a set of renderable objects and contributes them to the scene each frame. Subclasses such as ImageLayer, VolumeLayer, and LabelLayer implement update to build or refresh those objects for the current view. Custom layers register objects with addObject and report readiness through setState.
Layers carry shared presentation state in opacity, blendMode, and occludes, and expose a lifecycle LayerState that observers can subscribe to. A layer instance may be attached to only one viewport at a time.
class Particles extends Layer {
public readonly type = "Particles";
constructor(points: PointProps[]) {
super();
this.addObject(new PointsRenderable(points));
this.setState("ready");
}
public update() {}
}
viewport.addLayer(new Particles(points));Extended by
Constructor
Creates a layer with the given presentation state.
new Layer(props?): Layer;| Parameter | Description |
|---|---|
props: LayerProps | Initialization properties. Defaults to {}. |
Types
ChannelProps
Appearance settings for a single image channel.
| Property | Description |
|---|---|
visible?: boolean | Whether the channel is drawn. Defaults to true. |
color?: ColorLike | The channel's tint color. Defaults to white. |
contrastLimits?: [number, number] | Intensity range shown. Defaults to the data range. |
opacity?: number | Channel opacity in [0, 1]. Defaults to 1. |
LayerState
The loading lifecycle state of a layer.
type LayerState = "initialized" | "loading" | "ready";BlendMode
How a layer's output blends with previously drawn content.
type BlendMode =
| "none"
| "normal"
| "additive"
| "subtractive"
| "multiply"
| "premultipliedOver";StateChangeCallback
A callback invoked after a layer's state changes.
type StateChangeCallback = (newState, prevState?) => void;LayerProps
Initialization properties for constructing a layer.
| Property | Description |
|---|---|
opacity?: number | Layer opacity in [0, 1]. Defaults to 1. |
blendMode?: BlendMode | How the layer blends. Defaults to "none". |
occludes?: boolean | Hides content behind. Inferred from blendMode. |
SliceCoordinates
World-space coordinates selecting the data to display.
PointPickingResult
The result of picking a value from a layer with a click.
| Property | Description |
|---|---|
world: vec3 | The picked position in world units. |
value: number | The data value sampled at the position. |
SliceOrientation
The plane a 2D slice lies on, named by its in-plane axes.
type SliceOrientation = "XY" | "XZ" | "YZ";Properties
type
A string identifying the concrete layer type.
abstract readonly type: string;blendMode
How the layer's output blends with previously drawn content. Also applies to blending between objects within the layer.
blendMode: BlendMode;occludes
Whether the layer writes depth and hides content drawn behind it.
Occluding layers render a depth pass and always draw before non-occluding layers regardless of their order in the viewport. When not set explicitly this value is inferred from blendMode at construction only. Reassigning blendMode later does not update it.
occludes: boolean;requiresSceneDepth_
Set to true by subclasses whose shaders read scene depth.
protected requiresSceneDepth_: boolean = false;Accessors
requiresSceneDepth boolean
Whether the layer's shaders read scene depth. When true the renderer draws occluding layers to a depth texture the layer's shaders can sample. A layer cannot both occlude and read scene depth.
get requiresSceneDepth(): boolean;opacity number
The layer's opacity in [0, 1]. Values outside are clamped.
get opacity(): number;set opacity(value): void;| Parameter | Description |
|---|---|
value: number | The new opacity in [0, 1]. |
coverageGroups ReadonlyMap<number | null, readonly RenderableObject[]>
The layer's renderable objects grouped by coverage group. Objects in a group draw each pixel at most once, letting chunks at multiple levels of detail overlap correctly.
get coverageGroups(): ReadonlyMap<number | null, readonly RenderableObject[]>;state LayerState
The layer's current lifecycle state.
get state(): LayerState;Methods
update() void
Builds or refreshes the layer's renderable objects for the current view. Called automatically once per frame for every layer in a viewport.
abstract update(viewport?): void;| Parameter | Description |
|---|---|
viewport?: Viewport | The viewport being rendered. |
onEvent() void
Handles a pointer or wheel event from the owning viewport. Called automatically for each event before the camera controls. The default implementation does nothing.
onEvent(_event): void;| Parameter | Description |
|---|---|
_event: EventContext | The event with clip and world coordinates attached. |
onAttached() void
Lifecycle hook that is called automatically when a layer is is attached to a viewport. A layer can only be attached to one viewport at a time.
onAttached(context): void;| Parameter | Description |
|---|---|
context: IdetikContext | The shared runtime context. |
onDetached() void
Lifecycle hook that is called automatically when a layer is detached from a viewport.
onDetached(context): void;| Parameter | Description |
|---|---|
context: IdetikContext | The shared runtime context. |
addStateChangeCallback() void
Registers a callback invoked after every state change.
addStateChangeCallback(callback): void;| Parameter | Description |
|---|---|
callback: StateChangeCallback | Receives the new and previous states. |
removeStateChangeCallback() void
Removes a previously registered state change callback.
removeStateChangeCallback(callback): void;| Parameter | Description |
|---|---|
callback: StateChangeCallback | The callback to remove. |
setState() void
Sets the lifecycle state and notifies state change callbacks.
protected setState(newState): void;| Parameter | Description |
|---|---|
newState: LayerState | The state to enter. |
addObject() void
Registers a renderable object for drawing. Objects in the same coverage group draw each pixel at most once.
protected addObject(object, coverageGroup?): void;| Parameter | Description |
|---|---|
object: RenderableObject | The object to add. |
coverageGroup: number | null | The group key. Defaults to null. |
clearObjects() void
Removes all registered renderable objects.
protected clearObjects(): void;getUniforms() Record<string, unknown>
Returns uniform name-value pairs applied to every object drawn by this layer. Override in subclasses that need custom shader uniforms.
getUniforms(): Record<string, unknown>;