import type Accessor from "../core/Accessor.js"; import type Collection from "../core/Collection.js"; import type ActiveLayerInfo from "./ActiveLayerInfo.js"; import type LinkChartView from "../views/LinkChartView.js"; import type { LayerInfo, LegendModelState } from "./types.js"; import type { MapViewOrSceneView } from "../views/MapViewOrSceneView.js"; import type { ActiveLayerInfoProperties } from "./ActiveLayerInfo.js"; import type { ReadonlyArrayOrCollection } from "../core/Collection.js"; export interface LegendModelProperties extends Partial> { /** * Collection of [ActiveLayerInfo](https://developers.arcgis.com/javascript/latest/references/core/legend/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](https://developers.arcgis.com/javascript/latest/references/core/legend/ActiveLayerInfo/) is removed from or added to this collection. */ activeLayerInfos?: ReadonlyArrayOrCollection; } /** * Manages the reactive content displayed by the [Legend component](https://developers.arcgis.com/javascript/latest/references/map-components/components/arcgis-legend/) * and by custom legends. It tracks supported layer views, maintains the hierarchy of * [ActiveLayerInfo](https://developers.arcgis.com/javascript/latest/references/core/legend/ActiveLayerInfo/) objects, and coordinates legend element generation as the view changes. * * @since 5.2 * @example * const legendModel = new LegendModel({ * view, * layerInfos: [{ layer: map.allLayers.getItemAt(0) }], * }); */ export default class LegendModel extends Accessor { constructor(properties?: LegendModelProperties); /** * Collection of [ActiveLayerInfo](https://developers.arcgis.com/javascript/latest/references/core/legend/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](https://developers.arcgis.com/javascript/latest/references/core/legend/ActiveLayerInfo/) is removed from or added to this collection. */ get activeLayerInfos(): Collection; set activeLayerInfos(value: ReadonlyArrayOrCollection); /** * Indicates whether to show the [Basemap](https://developers.arcgis.com/javascript/latest/references/core/Basemap/) layers in the legend. * * @default false */ accessor basemapLegendVisible: boolean; /** * Indicates whether to include [Ground](https://developers.arcgis.com/javascript/latest/references/core/Ground/) layers in the legend. * * @default false */ accessor groundLegendVisible: 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`. * * @default false * @see [respectLayerVisibility](https://developers.arcgis.com/javascript/latest/references/core/legend/LegendModel/#respectLayerVisibility) */ accessor hideLayersNotInCurrentView: 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 false */ accessor keepCacheOnDestroy: boolean; /** * Defines which layers and sublayers are shown in the legend, including any [basemap layers](https://developers.arcgis.com/javascript/latest/references/core/legend/LegendModel/#basemapLegendVisible) you want visible. * If not set, all layers in the map are displayed in the legend by default, including basemap layers when * [basemapLegendVisible](https://developers.arcgis.com/javascript/latest/references/core/legend/LegendModel/#basemapLegendVisible) is `true`. */ accessor layerInfos: LayerInfo[]; /** Indicates whether one or more active layer info objects are currently generating legend elements. */ get loading(): boolean; /** * If a layer uses a unique value renderer, only features that satisfy the layer's * [definition expression](https://developers.arcgis.com/javascript/latest/references/core/layers/mixins/FeatureLayerBase/#definitionExpression) * will be displayed in the legend when set to true. * * @default false * @see [FeatureLayerBase.definitionExpression](https://developers.arcgis.com/javascript/latest/references/core/layers/mixins/FeatureLayerBase/#definitionExpression) */ accessor respectLayerDefinitionExpression: 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](https://developers.arcgis.com/javascript/latest/references/core/layers/FeatureLayer/#legendEnabled) property * is set to `false`. * - If the view's scale is outside the visibility range * defined by the [ScaleRangeLayer.minScale](https://developers.arcgis.com/javascript/latest/references/core/layers/mixins/ScaleRangeLayer/#minScale) and * [ScaleRangeLayer.maxScale](https://developers.arcgis.com/javascript/latest/references/core/layers/mixins/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. * * @default true * @see [hideLayersNotInCurrentView](https://developers.arcgis.com/javascript/latest/references/core/legend/LegendModel/#hideLayersNotInCurrentView) */ accessor respectLayerVisibility: boolean; /** * The current state of the legend content. * * @default "disabled" */ get state(): LegendModelState; /** The map, scene, or link chart view whose layer views supply the legend content. */ accessor view: MapViewOrSceneView | LinkChartView | null | undefined; }