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
PointGeometryGeoJSON Point geometry
LineStringGeometryGeoJSON LineString geometry
PolygonGeometryGeoJSON Polygon geometry
LibreDrawGeometrySupported GeoJSON geometry union
Position[longitude, latitude] coordinate pair
FeaturePropertiesArbitrary key-value properties
LibreDrawOptionsConstructor options
ToolbarOptionsToolbar configuration
ToolbarPositionToolbar placement
ToolbarControlsWhich toolbar buttons to show
ModeName'idle' | 'draw-point' | 'draw-line' | 'draw' | 'select' | 'split' | 'setback'
ActionUndo/redo action interface
ActionType'create' | 'update' | 'delete' | 'split' | 'setback'
NormalizedInputEventUnified mouse/touch event
InputType'mouse' | 'touch'

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
selectionchangeSelectionChangeEventSelection changed
modechangeModeChangeEventMode 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);
});

Released under the MIT License.