Control to measure distance between points on a map.
npm i @mapbox-controls/ruler
import RulerControl from '@mapbox-controls/ruler';
import '@mapbox-controls/ruler/src/index.css';
map.addControl(new RulerControl(), 'bottom-right');
map.on('ruler.on', () => console.log('Ruler activated'));
map.on('ruler.off', () => console.log('Ruler deactivated'));
export type ControlOptions = {
units?: import("@turf/helpers").Units;
labelFormat?: (n: number) => string;
lineLayout?: import("mapbox-gl").LineLayerSpecification["layout"];
linePaint?: import("mapbox-gl").LineLayerSpecification["paint"];
markerLayout?: import("mapbox-gl").CircleLayerSpecification["layout"];
markerPaint?: import("mapbox-gl").CircleLayerSpecification["paint"];
labelLayout?: import("mapbox-gl").SymbolLayerSpecification["layout"];
labelPaint?: import("mapbox-gl").SymbolLayerSpecification["paint"];
invisible?: boolean;
};
event | description |
---|---|
ruler.on | ruler activated |
ruler.off | ruler deactivated |
Methods are useful for programmatic control (when option invisible
is true
):
activate(): void;
- activate controlsdeactivate(): void;
- deactivate controladdCoordinate(coordinate: [number, number]): void;
- add new coordinate