@watergis/maplibre-gl-terradraw
    Preparing search index...

    A custom Terra Draw mode that lets users place, edit, and drag freeform text labels anywhere on the map.

    Gesture Behaviour
    Click on the map Opens a textarea popup at the clicked location.
    Enter (or Submit button) Commits the label as a Point GeoJSON feature with a text property. Calls onTextCommit and fires the TerraDraw finish event.
    Shift+Enter Inserts a newline without committing.
    Escape (in popup) Dismisses the popup and deletes the uncommitted feature.
    Click outside open popup Commits any typed text, or dismisses if empty.
    Click near existing label Opens the textarea pre-filled with existing text (requires editable: true).
    Drag a committed label Handled by TerraDrawSelectMode when flags.text.feature.draggable is true.

    TerraDrawTextMode itself only stores Point features in the TerraDraw store. MaplibreTerradrawControl detects the text mode and maintains a separate {prefix}-text-labels MapLibre symbol layer that reads the text property from the GeoJSON source. This means the labels are rendered by MapLibre GL and support all standard text-* paint/layout properties.

    import { MaplibreTerradrawControl, TerraDrawTextMode } from '@watergis/maplibre-gl-terradraw';

    const control = new MaplibreTerradrawControl({
    modes: ['text', 'select', 'delete'],
    modeOptions: {
    text: new TerraDrawTextMode({
    editable: true,
    placeholder: 'Add a label…',
    styles: {
    textColor: '#1a1a1a',
    textSize: 14,
    textSelectedSize: 16,
    textHaloColor: '#ffffff',
    textHaloWidth: 2,
    textSelectedHaloColor: '#E0B03F'
    },
    onTextCommit: (id, text) => console.log(`${id}: ${text}`),
    }),
    },
    });

    map.addControl(control, 'top-right');

    Hierarchy

    • TerraDrawBaseDrawMode<Omit<TextModeStyling, "textFont">>
      • TerraDrawTextMode
    Index
    mode: string = 'text'
    options?: TextModeOptions
    • Internal

      Parameters

      • event: TerraDrawMouseEvent

      Returns void

    • Internal

      Parameters

      • event: TerraDrawKeyboardEvent

      Returns void

    • Internal

      Parameters

      • event: TerraDrawMouseEvent

      Returns void

    • Internal

      Parameters

      • feature: GeoJSONStoreFeatures

      Returns TerraDrawAdapterStyling

    • Parameters

      • feature: GeoJSONStoreFeatures

      Returns { reason?: string; valid: boolean }