import LegendViewModel from "@arcgis/core/widgets/Legend/LegendViewModel.js";const LegendViewModel = await $arcgis.import("@arcgis/core/widgets/Legend/LegendViewModel.js");- Inheritance:
- LegendViewModel→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 4.11
Provides the logic for the Legend widget and component, which displays a label and symbol for interpreting the Renderer of each layer in a map. This class may be used to create custom, interactive Legends.
- See also
Legend widget - Deprecated since 4.34. Use the Legend component instead.
Example
const legend = new Legend({ view: view, viewModel: new LegendViewModel({ view: view })});view.ui.add(legend, "bottom-left");Constructors
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Properties
| Property | Type | Class |
|---|---|---|
| | ||
| | ||
declaredClass readonly inherited | ||
| | ||
| | ||
loading readonly | | |
| | ||
| | ||
state 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
- 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 legendlegend.viewModel.hideLayersNotInCurrentView = true; 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
- Since
- ArcGIS Maps SDK for JavaScript 4.34
Indicates whether the viewModel is currently loading.
- Default value
- false
respectLayerDefinitionExpression
- Type
- boolean
- Since
- ArcGIS Maps SDK for JavaScript 4.34
If a layer uses a unique value render, 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
- 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:
- 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
Example
// Always displays legend elements for the map's layers// regardless of their minScale, maxScale, and legendEnabled propertieslegend.respectLayerVisibility = false; view
- Type
- MapViewOrSceneView | LinkChartView | null | undefined
The view from which the widget will operate.