EntityBase API
EntityBase API
EntityBase is the abstract base for all entities. Do not instantiate directly; use concrete types (LineEnt, CircleEnt, etc.).
Properties
| Property | Type | Default | Description |
|---|---|---|---|
id | string | Auto | Unique id |
type | string | — | Entity type id (set by subclass) |
color | number | 0x00ff00 | Stroke color (24-bit RGB) |
fillColor | number | 0 | Fill color |
fillOpacity | number | 0 | Fill opacity (0–1) |
lineWidth | number | 1 | Line width in pixels |
lineType | string | 'Continuous' | Linetype name |
ltScale | number | 1 | Linetype scale |
layer | string | '0' | Layer name |
visible | boolean | true | Visibility |
rotation | number | 0 | Rotation in radians |
editable | boolean | true | Editable |
selectableInReadonly | boolean | false | Selectable in browse mode |
minDisplayLevel | number | undefined | undefined | Min zoom level to show |
maxDisplayLevel | number | undefined | undefined | Max zoom level to show |
dynamic | boolean | false | Dynamic entity (redrawn every frame) |
Methods
boundingBox
boundingBox(): BBoxAxis-aligned bounding box.
Returns: BBox — [minX, minY, maxX, maxY].
toGeoJSON
toGeoJSON(): GeoJSON.Feature[]Convert to GeoJSON features for vjmap.
Returns: Feature[].
clone
clone(): EntityBaseDeep clone (new id).
Returns: New entity instance.
Example:
const copy = line.clone();
copy.color = 0xff0000;
cadLayer.addEntity(copy);translate
translate(dx: number, dy: number): voidTranslate the entity.
| Parameter | Type | Description |
|---|---|---|
dx | number | Delta X |
dy | number | Delta Y |
rotate
rotate(angle: number, cx?: number, cy?: number): voidRotate around a center.
| Parameter | Type | Description |
|---|---|---|
angle | number | Angle in radians |
cx | number | Center X (defaults to entity center) |
cy | number | Center Y |
scale
scale(sx: number, sy: number, cx?: number, cy?: number): voidScale the entity.
| Parameter | Type | Description |
|---|---|---|
sx | number | X scale |
sy | number | Y scale |
cx | number | Center X (defaults to entity center) |
cy | number | Center Y |
mirror
mirror(p1: Point2DLike, p2: Point2DLike): voidMirror across the line through two points.
| Parameter | Type | Description |
|---|---|---|
p1 | Point2DLike | Axis start |
p2 | Point2DLike | Axis end |
changed
changed(): voidMark geometry as changed and trigger redraw. Call after editing geometry.
styleChanged
styleChanged(): voidMark style as changed. Call after color, linetype, etc.
setModified
setModified(): voidMark entity modified (geometry and/or style).
hasDisplayLevelFilter
hasDisplayLevelFilter(): booleanReturns: Whether display-level filtering is set.
Custom properties
setCustomProperty
setCustomProperty(key: string, value: any, type?: CustomPropertyType): voidSet a custom property.
| Parameter | Type | Description |
|---|---|---|
key | string | Key |
value | any | Value |
type | CustomPropertyType | Optional type hint |
getCustomProperty
getCustomProperty(key: string): CustomPropertyValue | undefinedReturns: Value for key, or undefined.
removeCustomProperty
removeCustomProperty(key: string): voidRemove a custom property.
getAllCustomProperties
getAllCustomProperties(): Record<string, CustomPropertyValue>Returns: All custom properties.
Example:
entity.setCustomProperty('楼层', '3F', 'string');
entity.setCustomProperty('面积', 120.5, 'number');
const floor = entity.getCustomProperty('楼层');
const all = entity.getAllCustomProperties();Related types
BBox
type BBox = [minX: number, minY: number, maxX: number, maxY: number];GripPointDef
interface GripPointDef {
point: Point2D;
type: GripType;
onMove: (newPoint: Point2D) => void;
}GripType
type GripType = 'vertex' | 'edge' | 'center' | 'control' | 'custom';GripShape
type GripShape = 'square' | 'circle' | 'diamond' | 'triangle';PropertyInfo
Metadata for the property panel.
VertexListData
Vertex list for polylines and similar entities.
CustomPropertyType
type CustomPropertyType = 'string' | 'number' | 'boolean' | 'json';CustomPropertyValue
interface CustomPropertyValue {
value: any;
type: CustomPropertyType;
}