Skip to content

DistanceTool

DistanceTool is the distance measurement tool. It extends DrawTool. After the user clicks to draw a polyline on the map, the tool calculates and displays the length of each segment and the total length. It supports metric/imperial unit switching, configurable label formatting, and measuring multiple polylines.

js
import { DistanceTool } from "maptalks";

const distanceTool = new DistanceTool({
  metric: true,
  imperial: false
}).addTo(map);

Constructor

js
new DistanceTool(options)

Parameters:

  • options — DistanceTool options. Some properties match the DistanceTool.options table below; the rest are inherited from DrawTool.

options

NameTypeDescriptionDefault
languageStringThe language of measurement hints'zh-CN'
metricBooleanWhether metric units are enabledtrue
imperialBooleanWhether imperial units are enabledfalse
vertexSymbolObjectThe symbol for vertex labelsnull
labelOptionsObjectOptions for measurement labelsnull
decimalPlacesNumberThe number of decimal places in the result2
formatLabelContentFunctionA custom formatter for the label contentnull
clearButtonSymbolObjectThe symbol of the clear buttonnull

Member Methods

  • clear() — Clears all current measurement results.
  • getMeasureLayers(): Layer[] — Gets the layers used to render measurement results.
  • getLastMeasure(): number — Gets the last measurement result.
  • undo() — Undoes the last step.
  • redo() — Redoes the last step.