Constructor
Optionaloptions: MeasureControlOptionsPlugin control options
Protected_Protected_Protected OptionalcontrolProtecteddefaultProtectedeventsProtected OptionalmapProtectedmodeProtectedoptionsProtected OptionalterradrawThe precision of area value. Using setter to override the value if you want.
The flag of whether computing elevation. Default is false. Using setter to override the value if you want.
ProtectedcssCSS prefix for the control buttons. Default is empty string
The precision of distance value. It will be set different value when distance unit is changed. Using setter to override the value if you want.
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)
Default is auto. If auto is set, unit is converted depending on the value and selection of area unit. If a specific unit is specified, it returns the value always the same. If a selected unit is not the same type of unit either metric of imperial, it will be ignored, and auto will be applied.
Default is auto. If auto is set, the unit is converted automatically based on the value.
If a specific unit is specified (e.g., 'km', 'm', 'cm', 'mi', 'ft', 'in'), the value is always returned in that unit.
This property is only effective when distanceUnit is set to 'kilometers' or 'miles'.
If distanceUnit is set to other values (e.g., 'degrees', 'radians'), it will be ignored, and auto will be applied.
If you need to force other unit type, please use DistanceUnit property.
get the state of whether the control is expanded or collapsed
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
Measure unit symbols. If you want to change the default symbol, please overwrite the symbol by this option.
The unit of measurement can be metric or imperial. Default is metric. The measuring result will be recalculated once new value is set
Activate Terra Draw to start drawing
ProtectedaddAdd Terra Draw drawing mode button
Terra Draw mode name
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})
maplibre style spec
Optionaloptions: { excludeTerraDrawLayers?: boolean; onlyTerraDrawLayers?: boolean }OptionalexcludeTerraDrawLayers?: booleanreturn maplibre style without terradraw layers and sources
OptionalonlyTerraDrawLayers?: booleanreturn maplibre style with only terradraw layers and sources
ProtectedclearClear GeoJSON feature related to extended control such as measure and valhalla by TerraDraw feature ID
the array of source ID to delete
the array of feature ID. Optional, if undefined, delete all labels for source
void
Deactivate Terra Draw to stop drawing
ProtecteddispatchDispatch an event. Pass the current snapshot of features and mode
event type
Optionalargs: { [key: string]: unknown }additional arguments
Get the default control position
default control position. Default is 'top-right'
get GeoJSON features
If true, returns only selected features. Default is false.
FeatureCollection in GeoJSON format
Get the Terra Draw instance. For the Terra Draw API, please refer to https://terradraw.io/#/api
Terra Draw instance with additional extensions for the plugin control
ProtectedhandleDownload button click event handler
ProtectedhandleHandle mode change operations that should be executed after setMode is called
The active mode name
The Terra Draw instance
The result of the setMode operation
add the plugin control to maplibre
Maplibre Map object
HTML Element
Remove the plugin control from maplibre
void
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()
})
Reset active mode to back to render mode
ProtectedsyncSynchronize button states with the current Terra Draw mode
The active mode name
ProtectedtoggleToggle the state of buttons when there is no features
ProtectedtoggleToggle the state of delete-select button
ProtectedtoggleToggle editor control
Maplibre GL Terra Draw Measure Control