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 polygon feature with id, geometry, and properties
PolygonGeometryGeoJSON Polygon geometry
Position[longitude, latitude] coordinate pair
FeaturePropertiesArbitrary key-value properties
LibreDrawOptionsConstructor options
ToolbarOptionsToolbar configuration
ToolbarPositionToolbar placement
ToolbarControlsWhich toolbar buttons to show
ModeName'idle' | 'draw' | 'select' | 'split' | 'setback'
ActionUndo/redo action interface
ActionType'create' | 'update' | 'delete' | 'split' | 'setback'
NormalizedInputEventUnified mouse/touch event
InputType'mouse' | 'touch'

Events

EventPayloadDescription
createCreateEventPolygon created
updateUpdateEventPolygon edited
deleteDeleteEventPolygon deleted
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.