Skip to content
import ActiveLayerInfo from "@arcgis/core/widgets/Legend/support/ActiveLayerInfo.js";
Inheritance:
ActiveLayerInfoAccessor
Since
ArcGIS Maps SDK for JavaScript 4.11

ActiveLayerInfo is added to or removed from the collection of Legend.activeLayerInfos as layers become visible or invisible in the view. You can use this module to make the Legend more interactive.

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
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.

children

Property
Type
Collection<ActiveLayerInfo>

A collection of child activeLayerInfos. This only applies to renderers of Sublayers or the children of GroupLayers.

cssEffectFilter

readonly Property
Type
string | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.34

The CSS filter string for the effects of the active layer.

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor

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

hideLayersNotInCurrentView

Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.21

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
Example
// layers not displayed in the view
// will not be shown in the legend
legend.hideLayersNotInCurrentView = true;

isScaleDriven

readonly Property
Type
boolean

Indicates if the legend's display of the layer's renderer is driven by the scale of the view. This is true of Sublayer renderers, any renderer that uses a valueExpression (Arcade expression), DotDensityRenderer, and layers that have FeatureReductionLayer.featureReduction enabled.

layer

Property
Type
Layer

The layer represented by the ActiveLayerInfo object.

layerView

Property
Type
LayerView

The layerView represented by the ActiveLayerInfo object's layer.

legendElements

Property
Type
LegendElement[]

The legendElements is constructed using the layer Renderer. It reflects the actual structure of the legend.

opacity

readonly Property
Type
number
Since
ArcGIS Maps SDK for JavaScript 4.17

The opacity of the layer or parent element.

parent

Property
Type
ActiveLayerInfo | null | undefined

The ActiveLayerInfo of the parent Sublayer or GroupLayer.

ready

readonly Property
Type
boolean

Indicates if the activeLayerInfo is ready. It is set to true when all its legendElements are computed. It is set to false when the layer renderer changes so that the legendElements can recomputed.

respectLayerVisibility

Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.13

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
Example
// Always displays legend elements for the map's layers
// regardless of their minScale, maxScale, and legendEnabled properties
legend.respectLayerVisibility = false;

scale

readonly Property
Type
number

The scale of the view instance in which the Legend is rendered.

sublayerIds

Property
Type
number[]
Since
ArcGIS Maps SDK for JavaScript 4.23

Only applies if the layer is a MapImageLayer. An array of MapImageLayer Sublayer IDs for which to display legend information. For example, if a MapImageLayer contains 100 sublayers, but you want to display the legend for two sublayers, then specifying the IDs of both sublayers will allow the Legend to only display legend information for those sublayers.

Example
// Only displays legend items for sublayers 1 and 2
activeLayerInfo.sublayerIds = [1, 2];

title

Property
Type
string | null | undefined

The text string that represents the legend's title. This value is read from the layerInfo of the corresponding layer in the legend. If not provided, this value comes from the Layer.title.

version

readonly Property
Type
number

The version of the ActiveLayerInfo. It increases by 1 whenever ready property of ActiveLayerInfo changes. This property should watched in the view for ActiveLayerInfo changes and update the DOM accordingly.

view

Property
Type
MapViewOrSceneView

The view in which the Legend is rendered.