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

    Maplibre GL Terra Draw Measure Control

    Hierarchy (View Summary)

    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 areaUnit(): areaUnitType

      Default is undefined. If undefined is set, the unit is converted automatically based on the value.

      For metric system:

      • Values >= 1,000,000m² are converted to square kilometers
      • Values >= 10,000m² are converted to hectares
      • Values >= 100m² are converted to ares
      • Values < 100m² are kept as square meters

      For imperial system:

      • Values >= 2,589,988.11m² (1 square mile) are converted to square miles
      • Values >= 4,046.856m² (1 acre) are converted to acres
      • Values >= 0.83612736m² (1 square yard) are converted to square yards
      • Values < 0.83612736m² are converted to square feet

      If a specific unit is specified (e.g., 'square meters', 'square kilometers', 'ares', 'hectares', 'square feet', 'square yards', 'acres', 'square miles'), the value is always returned in that unit.

      Custom conversion function can be also set to this property. The function receives the area value in square meters and should return an object with area and unit properties.

      An example of custom conversion function:

      const customConversion: AreaUnitCallBackType = (valueInSquareMeters) => {
      if (valueInSquareMeters >= 1000) {
      return { area: valueInSquareMeters / 1000, unit: 'km²' };
      } else {
      return { area: valueInSquareMeters, unit: 'm²' };
      };
      control.areaUnit = customConversion;

      Returns areaUnitType

    • set areaUnit(value: areaUnitType): void

      Parameters

      Returns void

    • get cssPrefix(): string

      CSS prefix for the control buttons. Default is empty string

      Returns string

    • get distanceUnit(): distanceUnitType

      Default is undefined. If undefined is set, the unit is converted automatically based on the value.

      For metric system:

      • Values >= 1000m are converted to kilometers
      • Values >= 1m are kept as meters
      • Values < 1m are converted to centimeters

      For imperial system:

      • Values >= 5280ft (1 mile) are converted to miles
      • Values >= 1ft are kept as feet
      • Values < 1ft are converted to inches

      If a specific unit is specified (e.g., 'km', 'm', 'cm', 'mi', 'ft', 'in'), the value is always returned in that unit.

      Custom conversion function can be also set to this property. The function receives the distance value in meters and should return an object with distance and unit properties. An example of custom conversion function:

      const customConversion: DistanceUnitCallBackType = (valueInMeter) => {
      if (valueInMeter >= 1000) {
      return { distance: valueInMeter / 1000, unit: 'km' };
      } else {
      return { distance: valueInMeter, unit: 'm' };
      };
      };
      control.distanceUnit = customConversion;

      Returns distanceUnitType

    • set distanceUnit(value: distanceUnitType): void

      Parameters

      Returns void

    • get fontGlyphs(): string[]

      Get/Set font glyph for measure control layers

      As default, this maesure control uses maplibre's default font glyphs(Open Sans Regular,Arial Unicode MS Regular) described at https://maplibre.org/maplibre-style-spec/layers/#text-font

      If you are using your own maplibre style or different map privider, you probably need to set the font glyphs to match 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 MaplibreMeasureControl()
      drawControl.fontGlyphs = ['Open Sans Italic']
      map.addControl(drawControl)

      Returns string[]

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

      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)

      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

    • 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

    • 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

    • 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

    • Recalculate area and distance in TerraDraw snapshot

      if you use addFeatures to restore GeoJSON features to TerraDraw, this recalc method needs to be called to re-measure again.

      For example, the below code is an example usage.

      drawInstance?.addFeatures(initData);
      map?.once('idle', ()=>{
      drawControl.recalc()
      })

      Returns void

    • 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