Maps Web SDK
Class L.DistanceMeasurement
Extends | L.Control |
Category | Widgets |
This widget allows the user to do distance measurements over the map.
Basic example
var map = new L.Map('map', {
key: "your-key",
center: [52.373154, 4.890659],
zoom: 13
});
var widget = new L.DistanceMeasurement();
widget.addTo(map);
Using options
var map = new L.Map('map', {
key: "your-api-key",
center: [52.373154, 4.890659],
zoom: 13
});
var widget = new L.DistanceMeasurement({
unitScheme: 'imperial',
markerColor: '#99ff99'
});
map.addControl(widget);
Constructor
L.DistanceMeasurement([options])
Parameters
Name | Description | Required | Type/Values | Default |
---|---|---|---|---|
options | No | Object | None | |
options.position | Decides the location of the widget | No | "topleft" | "topright" | "bottomleft" | "bottomright" | "topright" |
options.markerColor | Color of the markers used for each step of the ruler | No | String | "#000" |
options.lineColor | Color or the ruler's line | No | String | "#000" |
options.unitScheme | Indicate if the imperial measurement unit should be used for calculate the distances. If the value is null the widget will use the global unit measurement configuration. | No | "metric" | "imperial" | Null | null |
options.useArc | Display great circle arcs instead of rect lines | No | Boolean | false |
Methods
activate( )
Activate the widget displaying the measurement controls and wait for the user to click over the map to start the first measurement.
This method is called automatically when the user press over the widget's main button.
deactivate( )
Deactivate the widget cleaning all the rulers over the map and hiding the measurement controls.
If a measurement was in progress, it will be cancel first.
disable( ): L.DistanceMeasurement Chainable
Disables the widget's instance to not allowing user interaction.
Returns
enable( ): L.DistanceMeasurement Chainable
Re-enables the widget if was previously disabled.
Returns
redrawRulers( )
Destroy and create again all the visible rulers with the current widget options.
Useful when the options are changed and you need to apply them to all the previous measurements.
toggleActivation( ): L.DistanceMeasurement Chainable
Activate or deactivate the widget depending of its current state.
Returns
Events
L.DistanceMeasurement.Events.Activated
L.DistanceMeasurement.Events.Cancelled
L.DistanceMeasurement.Events.Changed
Properties
Name | Description | Type/Values | Default |
---|---|---|---|
ruler | Reference to the ruler instance | MeasurementRuler | None |
newSegment | The coordinates of the last new segment added | L.LatLng | None |
distance | Total ruler distance in meters after adding the new segment | Number | None |
L.DistanceMeasurement.Events.Deactivated
L.DistanceMeasurement.Events.Disabled
L.DistanceMeasurement.Events.Enabled
L.DistanceMeasurement.Events.Finished
Properties
Name | Description | Type/Values | Default |
---|---|---|---|
ruler | Reference to the ruler instance | MeasurementRuler | None |
distance | Total ruler distance in meters | Number | None |