Skip to content

Measurement Tool

mapprism-2d includes a built-in measurement workflow for distance and area tasks.

It supports both UI-driven usage and API-driven integration.


What it supports

  • repeatable line measurements
  • repeatable area measurements
  • interactive delete mode
  • programmatic access to saved drawings

Start a measurement session

ts
map.tools.measurement.startLine(); // distance mode
// or
map.tools.measurement.startArea(); // area mode

Interaction behavior:

  • Click to place vertices
  • Press Enter to finalize current drawing and continue in the same mode
  • Press Escape to cancel the in-progress drawing

Delete existing drawings

ts
map.tools.measurement.startDelete();
// click a drawing to remove it
map.tools.measurement.stopDelete();

This is useful in field workflows where users iteratively annotate and clean up map measurements during review.


Programmatic control

ts
const drawings = map.tools.measurement.getDrawings();

if (drawings.length > 0) {
  map.tools.measurement.deleteById(drawings[0].id);
}

map.tools.measurement.clear(); // remove all drawings
map.tools.measurement.stop();  // stop active measurement mode

Use getDrawings() when you need to:

  • persist user analysis
  • generate reports
  • pass measurement state into another part of your application

Built-in controls configuration

By default, top-right measurement controls are enabled:

ts
const config = {
  map2d: {
    tools: {
      measurement: {
        controls: true,
      },
    },
  },
};

For fully custom host UI, disable built-in controls and invoke the tool methods yourself:

ts
const config = {
  map2d: {
    tools: {
      measurement: {
        controls: false,
      },
    },
  },
};