Skip to content

Types

All types are exported as TypeScript type-only exports from @sindicum/libre-draw.

ts
import type {
  LibreDrawFeature,
  FeatureCollection,
  PointGeometry,
  LineStringGeometry,
  PolygonGeometry,
  LibreDrawGeometry,
  Position,
  FeatureProperties,
  LibreDrawOptions,
  ToolbarOptions,
  ToolbarPosition,
  ToolbarControls,
  StyleConfig,
  PartialStyleConfig,
  FillStyle,
  OutlineStyle,
  VertexStyle,
  PreviewStyle,
  EditVertexStyle,
  MidpointStyle,
  PointStyle,
  ModeName,
  Action,
  ActionType,
  NormalizedInputEvent,
  InputType,
} from '@sindicum/libre-draw';

Feature Types

Position

A geographic coordinate pair [longitude, latitude].

ts
type Position = [number, number];
IndexRangeDescription
0-180 to 180Longitude
1-90 to 90Latitude

PointGeometry

GeoJSON Point geometry.

ts
interface PointGeometry {
  type: 'Point';
  coordinates: Position;
}
PropertyTypeDescription
type'Point'Always 'Point'
coordinatesPositionA single [longitude, latitude] coordinate

LineStringGeometry

GeoJSON LineString geometry.

ts
interface LineStringGeometry {
  type: 'LineString';
  coordinates: Position[];
}
PropertyTypeDescription
type'LineString'Always 'LineString'
coordinatesPosition[]Array of [longitude, latitude] coordinates. Minimum 2 positions required.

PolygonGeometry

GeoJSON Polygon geometry.

ts
interface PolygonGeometry {
  type: 'Polygon';
  coordinates: Position[][];
}
PropertyTypeDescription
type'Polygon'Always 'Polygon'
coordinatesPosition[][]Array of linear rings. The first ring is the outer boundary. Each ring must be closed (first position === last position).

LibreDrawGeometry

Union of supported GeoJSON geometry types.

ts
type LibreDrawGeometry = PointGeometry | LineStringGeometry | PolygonGeometry;

FeatureProperties

Arbitrary key-value properties attached to a feature.

ts
interface FeatureProperties {
  [key: string]: unknown;
}

LibreDrawFeature

A GeoJSON Feature used by LibreDraw. Supports Point, LineString, and Polygon geometry types.

ts
interface LibreDrawFeature {
  id: string;
  type: 'Feature';
  geometry: LibreDrawGeometry;
  properties: FeatureProperties;
}
PropertyTypeDescription
idstringUUID v4 unique identifier
type'Feature'Always 'Feature'
geometryLibreDrawGeometryPoint, LineString, or Polygon geometry
propertiesFeaturePropertiesArbitrary metadata

FeatureCollection

A GeoJSON FeatureCollection containing LibreDraw features (points, lines, and polygons). Returned by toGeoJSON().

ts
interface FeatureCollection {
  type: 'FeatureCollection';
  features: LibreDrawFeature[];
}
PropertyTypeDescription
type'FeatureCollection'Always 'FeatureCollection'
featuresLibreDrawFeature[]Array of point and polygon features

Configuration Types

LibreDrawOptions

Options for creating a LibreDraw instance.

ts
interface LibreDrawOptions {
  toolbar?: boolean | ToolbarOptions;
  historyLimit?: number;
  style?: PartialStyleConfig;
  snap?: boolean | SnapConfig;
}
PropertyTypeDefaultDescription
toolbarboolean | ToolbarOptionstrueWhether to show the toolbar, or toolbar configuration. Set to false for headless mode.
historyLimitnumber100Maximum number of undo/redo history entries
stylePartialStyleConfigdefault stylePartial overrides for map layer styling (fill/outline/vertices/preview/edit handles).
snapboolean | SnapConfigtrueWhether to enable snapping, or snap configuration. Set to false to disable.

ToolbarOptions

Configuration options for the toolbar.

ts
interface ToolbarOptions {
  position?: ToolbarPosition;
  controls?: ToolbarControls;
}
PropertyTypeDefaultDescription
positionToolbarPosition'top-right'Where to place the toolbar on the map
controlsToolbarControlsAll trueWhich buttons to display

ToolbarPosition

Position of the toolbar control on the map.

ts
type ToolbarPosition =
  | 'top-left'
  | 'top-right'
  | 'bottom-left'
  | 'bottom-right';

ToolbarControls

Configuration for which toolbar controls to display.

ts
interface ToolbarControls {
  drawPoint?: boolean;
  drawLine?: boolean;
  draw?: boolean;
  select?: boolean;
  split?: boolean;
  setback?: boolean;
  settings?: boolean;
  delete?: boolean;
  undo?: boolean;
  redo?: boolean;
}
PropertyTypeDefaultDescription
drawPointbooleantrueShow draw-point mode toggle button
drawLinebooleantrueShow draw-line mode toggle button
drawbooleantrueShow draw mode toggle button
selectbooleantrueShow select mode toggle button
splitbooleantrueShow split mode toggle button
setbackbooleantrueShow setback mode toggle button and distance input
settingsbooleantrueShow style settings button and panel
deletebooleantrueShow delete button
undobooleantrueShow undo button
redobooleantrueShow redo button

Mode Types

ModeName

The available drawing mode names.

ts
type ModeName = 'idle' | 'draw-point' | 'draw-line' | 'draw' | 'select' | 'split' | 'setback';
ValueDescription
'idle'No drawing interaction. Map behaves normally.
'draw-point'Place point features by clicking/tapping.
'draw-line'Create lines by clicking/tapping vertices, double-click to finalize.
'draw'Create polygons by clicking/tapping vertices.
'select'Select and edit existing features (points, lines, and polygons).
'split'Split a polygon into two polygons with a two-point line.
'setback'Apply inward edge setback with distance input and preview.

Action Types

ActionType

The type of history action.

ts
type ActionType = 'create' | 'update' | 'delete' | 'split' | 'setback';

Action

A reversible action that can be applied and reverted on a FeatureStore.

ts
interface Action {
  type: ActionType;
  apply(store: FeatureStoreInterface): void;
  revert(store: FeatureStoreInterface): void;
}
PropertyTypeDescription
typeActionTypeThe kind of action
apply(store) => voidApply the action to the store
revert(store) => voidRevert the action from the store

FeatureStoreInterface

Minimal interface for the FeatureStore used by actions. This avoids circular imports between types and core modules.

ts
interface FeatureStoreInterface {
  add(feature: LibreDrawFeature): void;
  update(id: string, feature: LibreDrawFeature): void;
  remove(id: string): void;
  getById(id: string): LibreDrawFeature | undefined;
}

Input Types

InputType

The type of input device that generated an event.

ts
type InputType = 'mouse' | 'touch';

NormalizedInputEvent

A normalized input event shared across mouse and touch handlers.

ts
interface NormalizedInputEvent {
  lngLat: { lng: number; lat: number };
  point: { x: number; y: number };
  originalEvent: MouseEvent | TouchEvent;
  inputType: InputType;
}
PropertyTypeDescription
lngLat{ lng: number; lat: number }The geographic coordinate at the event location
point{ x: number; y: number }The screen pixel coordinate at the event location
originalEventMouseEvent | TouchEventThe original DOM event
inputTypeInputTypeThe input device type that generated this event

Style Types

StyleConfig

Full render style configuration. Returned by getStyle().

ts
interface StyleConfig {
  fill: FillStyle;
  outline: OutlineStyle;
  vertex: VertexStyle;
  preview: PreviewStyle;
  editVertex: EditVertexStyle;
  midpoint: MidpointStyle;
  point: PointStyle;
}
PropertyTypeDescription
fillFillStylePolygon fill rendering
outlineOutlineStylePolygon/line outline rendering
vertexVertexStyleVertex markers on features
previewPreviewStyleDraw preview / guide line
editVertexEditVertexStyleEdit vertex handles (selected features)
midpointMidpointStyleMidpoint handles (selected features)
pointPointStylePoint geometry features

PartialStyleConfig

Partial style overrides accepted by the constructor style option and setStyle(). All sections and properties are optional — unset values retain their current or default value.

ts
interface PartialStyleConfig {
  fill?: Partial<FillStyle>;
  outline?: Partial<OutlineStyle>;
  vertex?: Partial<VertexStyle>;
  preview?: Partial<PreviewStyle>;
  editVertex?: Partial<EditVertexStyle>;
  midpoint?: Partial<MidpointStyle>;
  point?: Partial<PointStyle>;
}

FillStyle

Style for polygon fill rendering.

ts
interface FillStyle {
  color: string;
  opacity: number;
  selectedColor: string;
  selectedOpacity: number;
}
PropertyTypeDefaultDescription
colorstring'#3bb2d0'Fill color
opacitynumber0.2Fill opacity (0–1)
selectedColorstring'#fbb03b'Fill color when selected
selectedOpacitynumber0.4Fill opacity when selected

OutlineStyle

Style for polygon/line outline rendering.

ts
interface OutlineStyle {
  color: string;
  width: number;
  selectedColor: string;
}
PropertyTypeDefaultDescription
colorstring'#3bb2d0'Line color
widthnumber2Line width in pixels
selectedColorstring'#fbb03b'Line color when selected

VertexStyle

Style for feature vertex markers displayed on all features.

ts
interface VertexStyle {
  color: string;
  strokeColor: string;
  strokeWidth: number;
  radius: number;
}
PropertyTypeDefaultDescription
colorstring'#ffffff'Vertex fill color
strokeColorstring'#3bb2d0'Vertex stroke color
strokeWidthnumber2Vertex stroke width
radiusnumber4Vertex radius in pixels

PreviewStyle

Style for draw preview and guide lines (split, setback).

ts
interface PreviewStyle {
  color: string;
  width: number;
  dasharray: number[];
}
PropertyTypeDefaultDescription
colorstring'#3bb2d0'Dash line color
widthnumber2Dash line width
dasharraynumber[][2, 2]Dash pattern

EditVertexStyle

Style for edit vertex handles on selected features.

ts
interface EditVertexStyle {
  color: string;
  strokeColor: string;
  strokeWidth: number;
  radius: number;
  highlightedColor: string;
  highlightedStrokeColor: string;
  highlightedRadius: number;
}
PropertyTypeDefaultDescription
colorstring'#ffffff'Handle fill color
strokeColorstring'#3bb2d0'Handle stroke color
strokeWidthnumber2Handle stroke width
radiusnumber5Handle radius
highlightedColorstring'#ff4444'Hover/highlight fill color
highlightedStrokeColorstring'#cc0000'Hover/highlight stroke color
highlightedRadiusnumber7Hover/highlight radius

MidpointStyle

Style for midpoint handles on selected features.

ts
interface MidpointStyle {
  color: string;
  opacity: number;
  radius: number;
}
PropertyTypeDefaultDescription
colorstring'#3bb2d0'Midpoint fill color
opacitynumber0.6Midpoint opacity
radiusnumber4Midpoint radius

PointStyle

Style for Point geometry features.

ts
interface PointStyle {
  color: string;
  radius: number;
  selectedColor: string;
  selectedRadius: number;
  hoverColor: string;
  strokeColor: string;
  strokeWidth: number;
}
PropertyTypeDefaultDescription
colorstring'#3bb2d0'Point fill color
radiusnumber6Point radius in pixels
selectedColorstring'#fbb03b'Point color when selected
selectedRadiusnumber8Point radius when selected
hoverColorstring'#fbb03b'Point color on mouse hover
strokeColorstring'#3bb2d0'Point stroke color
strokeWidthnumber2Point stroke width

Error Class

LibreDrawError

Base error class for all LibreDraw errors. Extends the native Error class.

ts
class LibreDrawError extends Error {
  constructor(message: string);
  name: 'LibreDrawError';
}

Thrown when:

  • A method is called on a destroyed instance
  • Invalid GeoJSON is passed to setFeatures or addFeatures
  • selectFeature is called with a non-existent feature ID
  • Invalid polygon geometry (self-intersecting, out-of-bounds coordinates, etc.)
ts
import { LibreDrawError } from '@sindicum/libre-draw';

try {
  draw.setFeatures({ invalid: 'data' });
} catch (e) {
  if (e instanceof LibreDrawError) {
    console.error('LibreDraw error:', e.message);
  }
}

Released under the MIT License.