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

    Maplibre GL Terra Draw Measure Control

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _cssPrefix: string = ''
    _isExpanded: boolean = false
    controlContainer?: HTMLElement
    defaultMode: string = 'render'
    events: { [key: string]: [(event: EventArgs) => void] } = {}
    map?: Map$1
    modeButtons: { [key: string]: HTMLButtonElement } = {}
    options: TerradrawControlOptions = defaultControlOptions
    terradraw?: TerraDraw

    Accessors

    • 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

      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

    Methods

    • 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

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

      Returns void

      void

    • get GeoJSON features

      Parameters

      • onlySelected: boolean = false

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

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

      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