▾
import LegendModel from "@arcgis/core/legend/LegendModel.js";const LegendModel = await $arcgis.import("@arcgis/core/legend/LegendModel.js");- Inheritance
- LegendModel→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 5.2
Manages the reactive content displayed by the Legend component and by custom legends. It tracks supported layer views, maintains the hierarchy of ActiveLayerInfo objects, and coordinates legend element generation as the view changes.
- Example
- const legendModel = new LegendModel({view,layerInfos: [{ layer: map.allLayers.getItemAt(0) }],});
Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | The properties used to configure the legend content. | |
Properties
| Property | Type | Class |
|---|---|---|
| | ||
| | ||
| readonly inherited | ||
| | ||
| | ||
| | ||
| | ||
| readonly | | |
| | ||
| | ||
| readonly | | |
| |
activeLayerInfos
- Type
- Collection<ActiveLayerInfo>
Collection of ActiveLayerInfo objects used by the legend view to display data in the legend. Use this property to hide or display the layer's symbols in the legend when an ActiveLayerInfo is removed from or added to this collection.
hideLayersNotInCurrentView
- Type
- boolean
When true, layers will only be shown in the legend if
they are visible in the view's extent. When data from a layer
is not visible in the view, the layer's legend information
will be hidden.
To hide layers completely
from the legend, you should set the legendEnabled property of
the layer to false.
- See also
- Default value
- false
keepCacheOnDestroy
- Type
- boolean
Indicates whether cached legend responses should be preserved when active layer info objects are destroyed. Preserving the cache can avoid repeating legend requests when rebuilding legend content.
- Default value
- false
layerInfos
- Type
- LayerInfo[]
Defines which layers and sublayers are shown in the legend, including any basemap layers you want visible.
If not set, all layers in the map are displayed in the legend by default, including basemap layers when
basemapLegendVisible is true.
loading
- Type
- boolean
Indicates whether one or more active layer info objects are currently generating legend elements.
respectLayerDefinitionExpression
- Type
- boolean
If a layer uses a unique value renderer, only features that satisfy the layer's definition expression will be displayed in the legend when set to true.
- Default value
- false
respectLayerVisibility
- Type
- boolean
Determines whether to respect the properties of the layers in the map that
control the legend's visibility (minScale, maxScale, legendEnabled).
By default, a layer's legend elements will
not render in the legend given the following conditions:
- The FeatureLayer.legendEnabled property
is set to
false. - If the view's scale is outside the visibility range defined by the ScaleRangeLayer.minScale and ScaleRangeLayer.maxScale properties.
When the respectLayerVisibility property of the legend is set to false, the legend elements for each
layer in the map will always display, thus disregarding the minScale, maxScale,
and legendEnabled properties for each layer in the map.
- See also
- Default value
- true
state
- Type
- LegendModelState
The current state of the legend content.
- Default value
- "disabled"
view
- Type
- MapViewOrSceneView | LinkChartView | null | undefined
The map, scene, or link chart view whose layer views supply the legend content.