API Reference
Overview
LibreDraw exposes a single entry-point class and a set of TypeScript types.
Main Class
| Export | Description |
|---|---|
LibreDraw | Main facade class — constructor, methods, and lifecycle |
Error Class
| Export | Description |
|---|---|
LibreDrawError | Error thrown by LibreDraw methods |
Types
All types are exported as TypeScript type-only exports:
| Type | Description |
|---|---|
LibreDrawFeature | A polygon feature with id, geometry, and properties |
PolygonGeometry | GeoJSON Polygon geometry |
Position | [longitude, latitude] coordinate pair |
FeatureProperties | Arbitrary key-value properties |
LibreDrawOptions | Constructor options |
ToolbarOptions | Toolbar configuration |
ToolbarPosition | Toolbar placement |
ToolbarControls | Which toolbar buttons to show |
ModeName | 'idle' | 'draw' | 'select' | 'split' | 'setback' |
Action | Undo/redo action interface |
ActionType | 'create' | 'update' | 'delete' | 'split' | 'setback' |
NormalizedInputEvent | Unified mouse/touch event |
InputType | 'mouse' | 'touch' |
Events
| Event | Payload | Description |
|---|---|---|
create | CreateEvent | Polygon created |
update | UpdateEvent | Polygon edited |
delete | DeleteEvent | Polygon deleted |
split | SplitEvent | Polygon split into two polygons |
splitfailed | SplitFailedEvent | Split operation failed |
setback | SetbackEvent | Setback operation succeeded |
setbackfailed | SetbackFailedEvent | Setback operation failed |
selectionchange | SelectionChangeEvent | Selection changed |
modechange | ModeChangeEvent | Mode switched |
Quick Example
ts
import { LibreDraw } from '@sindicum/libre-draw';
import type { LibreDrawFeature, CreateEvent } from '@sindicum/libre-draw';
const draw = new LibreDraw(map);
draw.on('create', (e: CreateEvent) => {
const feature: LibreDrawFeature = e.feature;
console.log(feature.id, feature.geometry.coordinates);
});