EntityStore API
EntityStore API
EntityStore is the central entity repository: CRUD, selection, spatial index, and draw order.
Access via cadLayer.store.
CRUD
add
add(entity: EntityBase): voidAdd an entity, update the spatial index, emit entity:added.
| Parameter | Type | Description |
|---|---|---|
entity | EntityBase | Entity |
delete
delete(id: string): voidDelete by id, emit entity:deleted.
| Parameter | Type | Description |
|---|---|---|
id | string | Entity id |
getById
getById(id: string): EntityBase | undefinedReturns: Entity or undefined.
getAll
getAll(): EntityBase[]Returns: All entities in draw order.
getAllIds
getAllIds(): string[]Returns: All entity ids.
Selection
select
select(id: string): voidAdd to selection, emit selection:changed.
deselect
deselect(id: string): voidRemove from selection.
toggleSelect
toggleSelect(id: string): voidToggle selection for one id.
clearSelection
clearSelection(): voidClear selection.
getSelectedIds
getSelectedIds(): string[]Returns: Selected ids.
getSelectedEntities
getSelectedEntities(): EntityBase[]Returns: Selected entities.
isSelected
isSelected(id: string): booleanReturns: Whether id is selected.
Example:
const store = cadLayer.store;
store.select(entity.id);
console.log(store.isSelected(entity.id)); // true
console.log(store.getSelectedIds()); // [entity.id]
store.clearSelection();Draw order
moveToFront
moveToFront(ids: string[]): voidMove to front (drawn last, on top).
moveToBack
moveToBack(ids: string[]): voidMove to back (drawn first, underneath).
moveUp
moveUp(ids: string[]): voidMove up one level.
moveDown
moveDown(ids: string[]): voidMove down one level.
Dirty flag
setDirty
setDirty(): voidMark the store dirty for the next render pass. Call after direct property edits if needed.
Properties
spatialIndex
readonly spatialIndex: SpatialIndexR-tree for spatial queries (box select, hit tests, etc.).
Example:
const hits = cadLayer.store.spatialIndex.search({
minX: 0, minY: 0,
maxX: 100, maxY: 100,
});