Skip to content

API Reference

Overview

LibreDraw exposes a single entry-point class and a set of TypeScript types.

Main Class

ExportDescription
LibreDrawMain facade class — constructor, methods, and lifecycle

Error Class

ExportDescription
LibreDrawErrorError thrown by LibreDraw methods

Types

All types are exported as TypeScript type-only exports:

TypeDescription
LibreDrawFeatureA Point, LineString, or Polygon feature with id, geometry, and properties
FeatureCollectionGeoJSON FeatureCollection of LibreDrawFeature
PointGeometryGeoJSON Point geometry
LineStringGeometryGeoJSON LineString geometry
PolygonGeometryGeoJSON Polygon geometry
LibreDrawGeometrySupported GeoJSON geometry union
Position[longitude, latitude] coordinate pair
FeaturePropertiesArbitrary key-value properties
LibreDrawOptionsConstructor options
KeyboardOptionsKeyboard shortcut configuration
SnapConfigSnapping configuration
ToolbarOptionsToolbar configuration
ToolbarPositionToolbar placement
ToolbarControlsWhich toolbar buttons to show
ModeName'idle' | 'draw-point' | 'draw-line' | 'draw-polygon' | 'draw-rectangle' | 'select' | 'split' | 'union' | 'setback' | 'rotate'
ActionUndo/redo action interface
ActionType'create' | 'update' | 'delete' | 'split' | 'setback' | 'union' | 'batch'
FeatureStoreInterfaceStore surface an Action applies to
StyleConfigFull render style (fill, outline, preview, edit handles, midpoints, points)
PartialStyleConfigPartial style overrides for the constructor and setStyle()
FillStyle, OutlineStyle, PreviewStyle, EditVertexStyle, MidpointStyle, PointStyleSections of StyleConfig
VertexStyleDeprecated. Kept for compatibility, has no effect
LibreDrawEventMapEvent name → payload map used by on() / off()
CreateEvent, UpdateEvent, DeleteEvent, SplitEvent, SplitFailedEvent, SetbackEvent, SetbackFailedEvent, UnionEvent, UnionFailedEvent, RotateEvent, SelectionChangeEvent, ModeChangeEvent, DraftChangeEventEvent payloads, see Events
SplitFailReason, SetbackFailReason, UnionFailReasonFailure reasons carried by the *failed events
NormalizedInputEventUnified mouse/touch event
InputType'mouse' | 'touch'
Locale'en' | 'ja'
MessagesUI strings of the toolbar and popups

Events

EventPayloadDescription
createCreateEventFeature created (point, line, or polygon)
updateUpdateEventFeature edited (point, line, or polygon)
deleteDeleteEventFeature deleted (point, line, or polygon)
splitSplitEventPolygon split into two polygons
splitfailedSplitFailedEventSplit operation failed
setbackSetbackEventSetback operation succeeded
setbackfailedSetbackFailedEventSetback operation failed
unionUnionEventTwo polygons merged into one
unionfailedUnionFailedEventUnion operation failed
rotateRotateEventFeature rotated
selectionchangeSelectionChangeEventSelection changed
modechangeModeChangeEventMode switched
draftchangeDraftChangeEventIn-progress drawing vertex count changed

Values

Runtime exports besides the two classes above:

ExportDescription
DEFAULT_STYLE_CONFIGThe built-in StyleConfig
mergeStyleConfigMerge partial overrides onto the defaults
BatchAction, SplitAction, SetbackAction, UnionActionAction 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);
});

Released under the MIT License.