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

    Maplibre GL Terra Draw Control

    Hierarchy (View Summary)

    Implements

    • IControl
    Index
    _cssPrefix: string = ''
    _fontGlyphs?: string[]
    _isExpanded: boolean = false
    controlContainer?: HTMLElement
    defaultMode: string = 'render'
    events: { [key: string]: [(event: EventArgs) => void] } = {}
    map?: Map$1
    modeButtons: { [key: string]: HTMLButtonElement } = {}
    terradraw?: TerraDraw
    • get fontGlyphs(): string[] | undefined

      Get/Set font glyph for the TextMode label layer ({prefix}-text-labels).

      As default, the TextMode label uses sans-serif so it is not constrained by the glyphs available in your maplibre style. See https://maplibre.org/maplibre-style-spec/layers/#text-font

      If you are using your own maplibre style or a different map provider, you probably need to set the font glyphs to match glyphs available in your maplibre style.

      Font glyph availability depends on what types of glyphs are supported by your maplibre style (e.g., Carto, Openmap tiles, Protomap, Maptiler, etc.). Please make sure the font glyphs are available in your maplibre style.

      Usage:

      const drawControl = new MaplibreTerradrawControl({ modes: ['text'] })
      drawControl.fontGlyphs = ['Open Sans Italic']
      map.addControl(drawControl)

      Returns string[] | undefined

    • set fontGlyphs(fontNames: string[]): void

      Parameters

      • fontNames: string[]

      Returns void

    • get isExpanded(): boolean

      get the state of whether the control is expanded or collapsed

      Returns boolean

    • set isExpanded(value: boolean): void

      set the state of the control either expanded or collapsed. terradraw mode will be reset if the state is changed. either expanded or collapsed event is dispatched when changed

      Parameters

      • value: boolean

      Returns void

    • get showDeleteConfirmation(): boolean

      Show delete confirmation popup when deleting features if true. Default is false

      Returns boolean

    • set showDeleteConfirmation(value: boolean): void

      Set show delete confirmation popup when deleting features if true. Default is false

      Parameters

      • value: boolean

      Returns void

    • Add Text Label Terradraw Features to the map

      Parameters

      • features: GeoJSONStoreFeatures<GeoJSONStoreGeometries>[]
      • map: Map$1
      • Optionalstyles: TextModeStyling

      Returns void

    • Apply the given font glyphs to the provided symbol layer specs and, when they already exist on the map, to their live layers via setLayoutProperty.

      Shared by subclasses (e.g. MaplibreMeasureControl, MaplibreValhallaControl) so their fontGlyphs setters can reuse the same layer-update logic.

      Parameters

      • fontNames: string[]

        font glyph names to apply as text-font

      • layers: (SymbolLayerSpecification | undefined)[]

        symbol layer specs to update (undefined entries are skipped)

      Returns void

    • clean maplibre style to filter only for terradraw related layers or without them. If options are not set, returns original style given to the function.

      This can be useful incase users only want to get terradraw related layers or without it.

      Usage: cleanStyle(map.getStyle, { excludeTerraDrawLayers: true}) cleanStyle(map.getStyle, { onlyTerraDrawLayers: true})

      Parameters

      • style: StyleSpecification

        maplibre style spec

      • Optionaloptions: { excludeTerraDrawLayers?: boolean; onlyTerraDrawLayers?: boolean }
        • OptionalexcludeTerraDrawLayers?: boolean

          return maplibre style without terradraw layers and sources

        • OptionalonlyTerraDrawLayers?: boolean

          return maplibre style with only terradraw layers and sources

      Returns StyleSpecification

    • Clear GeoJSON feature related to extended control such as measure and valhalla by TerraDraw feature ID

      Parameters

      • sourceIds: string[]

        the array of source ID to delete

      • ids: FeatureId[] | undefined = undefined

        the array of feature ID. Optional, if undefined, delete all labels for source

      Returns void

      void

    • Remove the {prefix}-text-labels symbol layer and the {prefix}-text GeoJSON source from the map.

      Called when all features are deleted via handleDeleteAllFeatures.

      Returns void

    • Create (or refresh) the MapLibre GL symbol layer used to render committed text labels from TerraDrawTextMode.

      Called automatically by onAdd when the text mode is active, and again after every TerraDraw finish event so newly committed labels appear immediately.

      1. Reads all committed text features from the TerraDraw snapshot (features where properties.mode === 'text' and properties.text is non-empty).
      2. If the {prefix}-text GeoJSON source already exists, calls setData to update it in place (no layer teardown/rebuild).
      3. If the source does not yet exist, adds the source and a {prefix}-text-labels symbol layer with defaults for text-field, text-size, text-font, text-color, and text-halo-*.
      4. Calls map.moveLayer('{prefix}-text-labels') to ensure the symbol layer renders above all other TerraDraw layers.

      The {prefix} comes from adapterOptions.prefixId (default 'td'), so with the default prefix the layer id is td-text-labels.

      Parameters

      • map: Map$1

        The MapLibre GL Map instance.

      • Optionalstyles: TextModeStyling

        Optional style overrides forwarded to the MapLibre symbol layer.

      Returns void

    • Handle deletion of symbol text layer when mode === 'text'

      Parameters

      • selectedFeatures: GeoJSONStoreFeatures<GeoJSONStoreGeometries>[]

      Returns void

    • Dispatch an event. Pass the current snapshot of features and mode

      Parameters

      • event: EventType

        event type

      • Optionalargs: { [key: string]: unknown }

        additional arguments

      Returns void

    • Get the default control position

      Returns ControlPosition

      default control position. Default is 'top-right'

    • get GeoJSON features

      Parameters

      • onlySelected: boolean = false

        If true, returns only selected features. Default is false.

      Returns
          | {
              features: GeoJSONStoreFeatures<GeoJSONStoreGeometries>[];
              type: string;
          }
          | undefined

      FeatureCollection in GeoJSON format

    • Handle the history event from TerraDraw to update undo/redo button states

      Parameters

      • event: { redoSize: number; undoSize: number }

        HistoryEvent from TerraDraw

      Returns void

    • Handle mode change operations that should be executed after setMode is called

      Parameters

      • mode: string

        The active mode name

      • target: TerraDraw

        The Terra Draw instance

      Returns void

      The result of the setMode operation

    • add the plugin control to maplibre

      Parameters

      • map: Map$1

        Maplibre Map object

      Returns HTMLElement

      HTML Element

    • Restore the default paint properties on the {prefix}-text-labels layer after a text feature is deselected.

      Resets text-color, text-halo-color, and text-halo-width from TextModeStyling defaults. Also refreshes the GeoJSON source to clear the TerraDraw selected flag from the feature data.

      Called automatically on terradraw.on('deselect').

      Returns void

    • Apply highlighted styles to the {prefix}-text-labels layer when a text feature is selected via TerraDrawSelectMode.

      Refreshes the GeoJSON source so the TerraDraw selected property is current, then sets data-driven text-size and text-halo-color expressions that make the selected label slightly larger and give it a white halo. If the selected feature is not a text feature, delegates to resetTextLabelLayer instead.

      Called automatically on terradraw.on('select').

      Parameters

      • featureId: FeatureId

        The TerraDraw feature ID that was selected.

      Returns void

    • Show delete confirmation dialog.

      Parameters

      • onConfirm: () => void

        Callback function that will be invoked when the user confirms deletion by clicking the "Delete" button in the dialog; typically used to delete all features before the dialog is closed.

      • title: string = 'Delete All Features'

        Optional dialog title. Defaults to 'Delete All Features'.

      • message: string = 'Are you sure you want to delete all features?'

        Optional dialog message. Defaults to 'Are you sure you want to delete all features?'.

      Returns void

    • Synchronize button states with the current Terra Draw mode

      Parameters

      • mode: string

        The active mode name

      Returns void