CAD Layers
Read CAD/PDF layer snapshots, listen for layer changes, and update layer visibility using the SDK.
Use viewer.layers to read CAD/PDF layer snapshots, listen for layer changes, and update layer visibility.
Layer commands are available after the viewer is mounted, Canvas is ready, and a CAD/PDF document is open.
Fetch current layers definition from the active drawing view:
getLayers()sends the CanvasgetLayersbroker message and waits for a matchinglayersSnapshot.
Subscribe to real-time layer state snapshot changes:
- The same event fires for snapshots requested with
getLayers()and snapshots emitted after visibility changes.
Use selectors returned in the layer row to show/hide layers. Vector CAD layers use index while PDF layers use id.
setLayerVisibility(...)sendssetLayerVisibilityand waits for the updatedlayersSnapshot.- Shorter alias
setVisibility(...)is also supported:
Visibility Shorter Alias
Use exactly one selector per visibility call:
index: One vector CAD layer index.indexes: Multiple vector CAD layer indices.id: One PDF layer ID.ids: Multiple PDF layer IDs.name: One layer display name.names: Multiple layer display names.all: Targets every layer.
Important types exported by the library for layer properties:
Type definitions for layer options:
Typing references exported directly by @rasterex/viewer:
Validation checks applied to layer configuration requests:
visiblemust be a boolean.- Exactly one selector must be provided.
indexmust be a non-negative integer.indexesmust be a non-empty array of non-negative integers.idmust be a non-empty string or finite number.idsmust be a non-empty array of non-empty strings or finite numbers.namemust not be empty.namesmust be a non-empty array of non-empty strings.getLayers(...)andsetLayerVisibility(...)reject if the matching snapshot is not received withintimeoutMs.
Complete integration code setup for Vanilla HTML/JS environments:
Broker message mapping for CAD layer APIs:
viewer.layers.getLayers(...)maps togetLayers.viewer.layers.setLayerVisibility(...)maps tosetLayerVisibility.viewer.layers.setVisibility(...)maps tosetLayerVisibility.viewer.layers.on("snapshot", ...)listens tolayersSnapshot.
Use the related pages below when you need the matching block workflow or the full payload reference.
- Blocks: Blocks
- Technical Reference: API References
- CAD Overview: Overview
