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 Point, LineString, or Polygon feature with id, geometry, and properties |
FeatureCollection | GeoJSON FeatureCollection of LibreDrawFeature |
PointGeometry | GeoJSON Point geometry |
LineStringGeometry | GeoJSON LineString geometry |
PolygonGeometry | GeoJSON Polygon geometry |
LibreDrawGeometry | Supported GeoJSON geometry union |
Position | [longitude, latitude] coordinate pair |
FeatureProperties | Arbitrary key-value properties |
LibreDrawOptions | Constructor options |
KeyboardOptions | Keyboard shortcut configuration |
SnapConfig | Snapping configuration |
ToolbarOptions | Toolbar configuration |
ToolbarPosition | Toolbar placement |
ToolbarControls | Which toolbar buttons to show |
ModeName | 'idle' | 'draw-point' | 'draw-line' | 'draw-polygon' | 'draw-rectangle' | 'select' | 'split' | 'union' | 'setback' | 'rotate' |
Action | Undo/redo action interface |
ActionType | 'create' | 'update' | 'delete' | 'split' | 'setback' | 'union' | 'batch' |
FeatureStoreInterface | Store surface an Action applies to |
StyleConfig | Full render style (fill, outline, preview, edit handles, midpoints, points) |
PartialStyleConfig | Partial style overrides for the constructor and setStyle() |
FillStyle, OutlineStyle, PreviewStyle, EditVertexStyle, MidpointStyle, PointStyle | Sections of StyleConfig |
VertexStyle | Deprecated. Kept for compatibility, has no effect |
LibreDrawEventMap | Event name → payload map used by on() / off() |
CreateEvent, UpdateEvent, DeleteEvent, SplitEvent, SplitFailedEvent, SetbackEvent, SetbackFailedEvent, UnionEvent, UnionFailedEvent, RotateEvent, SelectionChangeEvent, ModeChangeEvent, DraftChangeEvent | Event payloads, see Events |
SplitFailReason, SetbackFailReason, UnionFailReason | Failure reasons carried by the *failed events |
NormalizedInputEvent | Unified mouse/touch event |
InputType | 'mouse' | 'touch' |
Locale | 'en' | 'ja' |
Messages | UI strings of the toolbar and popups |
Events
| Event | Payload | Description |
|---|---|---|
create | CreateEvent | Feature created (point, line, or polygon) |
update | UpdateEvent | Feature edited (point, line, or polygon) |
delete | DeleteEvent | Feature deleted (point, line, or polygon) |
split | SplitEvent | Polygon split into two polygons |
splitfailed | SplitFailedEvent | Split operation failed |
setback | SetbackEvent | Setback operation succeeded |
setbackfailed | SetbackFailedEvent | Setback operation failed |
union | UnionEvent | Two polygons merged into one |
unionfailed | UnionFailedEvent | Union operation failed |
rotate | RotateEvent | Feature rotated |
selectionchange | SelectionChangeEvent | Selection changed |
modechange | ModeChangeEvent | Mode switched |
draftchange | DraftChangeEvent | In-progress drawing vertex count changed |
Values
Runtime exports besides the two classes above:
| Export | Description |
|---|---|
DEFAULT_STYLE_CONFIG | The built-in StyleConfig |
mergeStyleConfig | Merge partial overrides onto the defaults |
BatchAction, SplitAction, SetbackAction, UnionAction | Action classes recorded in the history, exported so integrations can recognise them |
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);
});