import LegendModel from "@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

Constructor

Parameters

ParameterTypeDescriptionRequired
properties

The properties used to configure the legend content.

See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.

activeLayerInfos

autocast Property
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.

basemapLegendVisible

Property
Type
boolean

Indicates whether to show the Basemap layers in the legend.

Default value
false

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor
Since
ArcGIS Maps SDK for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

groundLegendVisible

Property
Type
boolean

Indicates whether to include Ground layers in the legend.

Default value
false

hideLayersNotInCurrentView

Property
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

Property
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

Property
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

readonly Property
Type
boolean

Indicates whether one or more active layer info objects are currently generating legend elements.

respectLayerDefinitionExpression

Property
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.

See also
Default value
false

respectLayerVisibility

Property
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:

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

readonly Property
Type
LegendModelState

The current state of the legend content.

Default value
"disabled"

view

Property
Type
MapViewOrSceneView | LinkChartView | null | undefined

The map, scene, or link chart view whose layer views supply the legend content.