Class: Units

Units

ScaleBar module provides measurement scale visualization and unit conversion functionality. Includes both a base Units class for unit management and a ScaleBar class for visual representation.

Units class provides unit conversion and formatting capabilities. Supports various measurement units and automatic unit selection based on scale.


new Units( [options])

Creates a new Units instance.

Parameters:
Name Type Argument Description
options Object <optional>

Configuration options

Properties
Name Type Argument Default Description
units Array.<string> <optional>
['km', 'm', 'cm', 'mm', 'µm']

Available units in order of preference

allUnits Object.<string, number> <optional>

All supported units and their conversion factors to millimeters

precision number <optional>
2

Number of decimal places for formatted values

Source:

Methods


format(d [, unit])

Formats a measurement value with appropriate units. Automatically selects the best unit if none specified.

Parameters:
Name Type Argument Description
d number

Value to format (in millimeters)

unit string <optional>

Specific unit to use for formatting

Source:
Returns:

Formatted measurement with units (e.g., "5.00 mm" or "1.00 m")

Type
string
Example
const units = new Units();
units.format(1500);       // Returns "1.50 m"
units.format(1500, 'mm'); // Returns "1500.00 mm"