Legend Control
A legend control is responsible for managing the collection of legends currently visible within the context of an interface or map and provides the interface needed for adding and removing legends.
// Adds a legend control to the map, returning the control instance
const control = controller.addLegendControl(options);
// Removes the legend control
controller.removeLegendControl();
Configuration
The following configuration options are supported when instantiating LegendControl
instances:
Option | Description | Default |
---|---|---|
width | Type: number ()Width of the legend control. |
|
insets | Type: number or Array<number> ()Internal padding between the canvas edges and the legend content. If a single value is provided, then that inset is applied for all four sides. If an array of two numbers is provided, then the values indicate the horizontal and vertical insets respectively. |
|
metric | Type: boolean ()Whether the default units for legends should be in Metric values. |
|
toggleOnClick | Type: boolean ()Whether units should be toggled when clicking on the control. |
|
Properties
The following properties are available on LegendControl
instances:
Option | Description | Default |
---|---|---|
container | Type: HTMLElement (readonly)The DOM container for the control. |
|
metric | Type: boolean ()Whether units are currently in Metric. |
|
Methods
The following methods are available on LegendControl
instances:
addTo(target: HTMLElement | string)
remove()
addLegend(id: string, config: Partial<LegendOptions>): Legend
hasLegend(id: string): boolean
getLegend(id: string): Legend
removeLegend(id: string, force = false)
toggleUnits()
Events
The following events are triggered by LegendControl
instances.
add
remove
units:changed