Types
All types are exported as TypeScript type-only exports from @sindicum/libre-draw.
import type {
LibreDrawFeature,
FeatureCollection,
PolygonGeometry,
Position,
FeatureProperties,
LibreDrawOptions,
ToolbarOptions,
ToolbarPosition,
ToolbarControls,
ModeName,
Action,
ActionType,
NormalizedInputEvent,
InputType,
} from '@sindicum/libre-draw';Feature Types
Position
A geographic coordinate pair [longitude, latitude].
type Position = [number, number];| Index | Range | Description |
|---|---|---|
0 | -180 to 180 | Longitude |
1 | -90 to 90 | Latitude |
PolygonGeometry
GeoJSON Polygon geometry.
interface PolygonGeometry {
type: 'Polygon';
coordinates: Position[][];
}| Property | Type | Description |
|---|---|---|
type | 'Polygon' | Always 'Polygon' |
coordinates | Position[][] | Array of linear rings. The first ring is the outer boundary. Each ring must be closed (first position === last position). |
FeatureProperties
Arbitrary key-value properties attached to a feature.
interface FeatureProperties {
[key: string]: unknown;
}LibreDrawFeature
A GeoJSON Feature with Polygon geometry used by LibreDraw.
interface LibreDrawFeature {
id: string;
type: 'Feature';
geometry: PolygonGeometry;
properties: FeatureProperties;
}| Property | Type | Description |
|---|---|---|
id | string | UUID v4 unique identifier |
type | 'Feature' | Always 'Feature' |
geometry | PolygonGeometry | The polygon geometry |
properties | FeatureProperties | Arbitrary metadata |
FeatureCollection
A GeoJSON FeatureCollection containing LibreDraw polygons. Returned by toGeoJSON().
interface FeatureCollection {
type: 'FeatureCollection';
features: LibreDrawFeature[];
}| Property | Type | Description |
|---|---|---|
type | 'FeatureCollection' | Always 'FeatureCollection' |
features | LibreDrawFeature[] | Array of polygon features |
Configuration Types
LibreDrawOptions
Options for creating a LibreDraw instance.
interface LibreDrawOptions {
toolbar?: boolean | ToolbarOptions;
historyLimit?: number;
style?: PartialStyleConfig;
}| Property | Type | Default | Description |
|---|---|---|---|
toolbar | boolean | ToolbarOptions | true | Whether to show the toolbar, or toolbar configuration. Set to false for headless mode. |
historyLimit | number | 100 | Maximum number of undo/redo history entries |
style | PartialStyleConfig | default style | Partial overrides for map layer styling (fill/outline/vertices/preview/edit handles). |
ToolbarOptions
Configuration options for the toolbar.
interface ToolbarOptions {
position?: ToolbarPosition;
controls?: ToolbarControls;
}| Property | Type | Default | Description |
|---|---|---|---|
position | ToolbarPosition | 'top-right' | Where to place the toolbar on the map |
controls | ToolbarControls | All true | Which buttons to display |
ToolbarPosition
Position of the toolbar control on the map.
type ToolbarPosition =
| 'top-left'
| 'top-right'
| 'bottom-left'
| 'bottom-right';ToolbarControls
Configuration for which toolbar controls to display.
interface ToolbarControls {
draw?: boolean;
select?: boolean;
split?: boolean;
setback?: boolean;
delete?: boolean;
undo?: boolean;
redo?: boolean;
}| Property | Type | Default | Description |
|---|---|---|---|
draw | boolean | true | Show draw mode toggle button |
select | boolean | true | Show select mode toggle button |
split | boolean | true | Show split mode toggle button |
setback | boolean | true | Show setback mode toggle button and distance input |
delete | boolean | true | Show delete button |
undo | boolean | true | Show undo button |
redo | boolean | true | Show redo button |
Mode Types
ModeName
The available drawing mode names.
type ModeName = 'idle' | 'draw' | 'select' | 'split' | 'setback';| Value | Description |
|---|---|
'idle' | No drawing interaction. Map behaves normally. |
'draw' | Create polygons by clicking/tapping vertices. |
'select' | Select and edit existing 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.
type ActionType = 'create' | 'update' | 'delete' | 'split' | 'setback';Action
A reversible action that can be applied and reverted on a FeatureStore.
interface Action {
type: ActionType;
apply(store: FeatureStoreInterface): void;
revert(store: FeatureStoreInterface): void;
}| Property | Type | Description |
|---|---|---|
type | ActionType | The kind of action |
apply | (store) => void | Apply the action to the store |
revert | (store) => void | Revert the action from the store |
FeatureStoreInterface
Minimal interface for the FeatureStore used by actions. This avoids circular imports between types and core modules.
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.
type InputType = 'mouse' | 'touch';NormalizedInputEvent
A normalized input event shared across mouse and touch handlers.
interface NormalizedInputEvent {
lngLat: { lng: number; lat: number };
point: { x: number; y: number };
originalEvent: MouseEvent | TouchEvent;
inputType: InputType;
}| Property | Type | Description |
|---|---|---|
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 |
originalEvent | MouseEvent | TouchEvent | The original DOM event |
inputType | InputType | The input device type that generated this event |
Error Class
LibreDrawError
Base error class for all LibreDraw errors. Extends the native Error class.
class LibreDrawError extends Error {
constructor(message: string);
name: 'LibreDrawError';
}Thrown when:
- A method is called on a destroyed instance
- Invalid GeoJSON is passed to
setFeaturesoraddFeatures selectFeatureis called with a non-existent feature ID- Invalid polygon geometry (self-intersecting, out-of-bounds coordinates, etc.)
import { LibreDrawError } from '@sindicum/libre-draw';
try {
draw.setFeatures({ invalid: 'data' });
} catch (e) {
if (e instanceof LibreDrawError) {
console.error('LibreDraw error:', e.message);
}
}