Skip to content
import SelectionManager from "@arcgis/core/views/SelectionManager.js";
Inheritance:
SelectionManagerAccessor
Since
ArcGIS Maps SDK for JavaScript 5.0
beta

A selection manager controls the selection of features in layers and tables within a MapView or SceneView to help manage feature selection. It can be wired up to listen for edits made to selectable layers and have the selection update accordingly.

Example
// Create a selection manager and set its view.
// Then, add a layer to its sources.
const selectionManager = new SelectionManager({
view,
sources: [featureLayer]
});
// Select the features in the layer with specified Object IDs.
selectionManager.replace(featureLayer, [1, 2, 3]);

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.

count

readonly Property
Type
number

The total number of selected features across all sources.

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.

hasSelection

readonly Property
Type
boolean

Returns true if at least one source has an active selection.

highlightEnabled

Property
Type
boolean

Indicates whether to display a visual representation of the selection with a highlight.

Default value
true

highlightName

Property
Type
string

The highlights name to use when specifying a set of highlight options.

See also
Default value
"default"

selections

readonly Property
Type
LayerSelection[]

A read-only copy of the selection. To modify selections, use add, replace, remove, or toggle.

sources

autocast Property
Type
Collection<SelectableLayer>

A collection of selectable layers managed by the selection manager. Use syncSources to automatically populate this collection from the layers and tables in a MapView or SceneView.

When setting the sources property to an external Collection or array, the selection manager adds its contents to an internal Collection. Therefore, when the SelectionManager is destroyed, this internal sources Collection is always destroyed.

See also
Examples
// Create a selection manager and set its view.
// Then, add a layer to its sources.
const selectionManager = new SelectionManager({
view,
sources: [featureLayer]
});
// Later, if you want to add more layers, you can do so like this:
selectionManager.sources.add(anotherFeatureLayer);
// Or, if you want to replace the existing sources with a new set of layers:
selectionManager.sources = [differentFeatureLayer];

updating

readonly Property
Type
boolean

Indicates whether the selection manager is currently updating the view's visualization of selections.

Default value
false

view

Property
Type
View | null | undefined

A reference to the MapView, or SceneView. This property must be set if wanting to highlight a corresponding feature within the map when a row is selected. In addition, setting the view is required if working with layer views.

Methods

MethodSignatureClass
add
add(layer: GraphicsLayer, selection: Graphic[]): void
add
add(layer: SelectableLayerWithObjectIds, selection: ObjectId[] | Graphic[]): void
add
add(layer: SelectableLayer, selection: SelectionIdentifier[]): void
clear(): void
emit
inherited
emit<Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
getSelectedFeatures(includeLayers: SelectableLayerWithObjectIds[] | undefined, queryParams: QueryProperties | undefined, queryTarget?: "layerView" | "layer"): Promise<LayerFeatureSet[]>
getSelection(target: GraphicsLayer): Graphic[] | undefined
getSelection(target: SelectableLayerWithObjectIds): ObjectId[] | undefined
getSelection(target: SelectableLayer): SelectionIdentifier[] | undefined
hasEventListener
inherited
hasEventListener<Type extends EventNames<this>>(type: Type): boolean
on
inherited
on<Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
remove(layer: GraphicsLayer, selection: Graphic[]): void
remove(layer: SelectableLayerWithObjectIds, selection: ObjectId[] | Graphic[]): void
remove(layer: SelectableLayer, selection: SelectionIdentifier[]): void
replace(layer: GraphicsLayer, selection: Graphic[]): void
replace(layer: SelectableLayerWithObjectIds, selection: ObjectId[] | Graphic[]): void
replace(layer: SelectableLayer, selection: SelectionIdentifier[]): void
syncSources(): void
toggle(layer: GraphicsLayer, selection: Graphic[]): void
toggle(layer: SelectableLayerWithObjectIds, selection: ObjectId[] | Graphic[]): void
toggle(layer: SelectableLayer, selection: SelectionIdentifier[]): void

add

Method
Signature
add (layer: GraphicsLayer, selection: Graphic[]): void

Adds features to the current selection. It does not replace the existing selection.

Parameters
ParameterTypeDescriptionRequired
layer

The selectable layer to which to add the selection. This must be a layer with graphics in the sources.

selection

An array of features, ie. Graphic[] to add to the current selection.

Returns
void

add

Method
Signature
add (layer: SelectableLayerWithObjectIds, selection: ObjectId[] | Graphic[]): void

Adds features to the current selection. It does not replace the existing selection.

Parameters
ParameterTypeDescriptionRequired
layer

The selectable layer to which to add the selection. This must be a layer with object IDs in the sources.

selection

An array of features, ie. ObjectId[] to add to the current selection.

Returns
void

add

Method
Signature
add (layer: SelectableLayer, selection: SelectionIdentifier[]): void

Adds features to the current selection. It does not replace the existing selection.

Parameters
ParameterTypeDescriptionRequired
layer

The selectable layer to which to add the selection. This must be a layer in the sources. It can be a layer with graphics or object IDs.

selection

An array of features, ie. Graphic[] or ObjectId[] to add to the current selection.

Returns
void

clear

Method
Signature
clear (): void

Clears all selections from all layers.

Returns
void

emit

inherited Method
Signature
emit <Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin
Since
ArcGIS Maps SDK for JavaScript 4.5

Emits an event on the instance. This method should only be used when creating subclasses of this class.

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

event
this["@eventTypes"][Type]

The event payload.

Returns
boolean

true if a listener was notified

getSelectedFeatures

Method
Signature
getSelectedFeatures (includeLayers: SelectableLayerWithObjectIds[] | undefined, queryParams: QueryProperties | undefined, queryTarget?: "layerView" | "layer"): Promise<LayerFeatureSet[]>

Queries the selected features for one or more layers. It uses the current selection identifiers to fetch feature data from the layer which may include attributes, geometry, etc. depending on the layer's capabilities and the supplied queryParams.

Parameters
ParameterTypeDescriptionRequired
includeLayers

Specifies the layer from which to fetch features. If not provided, all layers with active selections are queried.

queryParams

If supplied, it may include any supplemental parameters to thin out the feature results. The object IDs will also be part of the generated query.

queryTarget
"layerView" | "layer"

If "layer", applies all queries to the layer itself rather than the layer view. This can be used to bypass any client-side filtering that may be applied within the layer view. Note that not all layers support querying on the layer itself, so this option should be used with caution. If a layer does not support querying on the layer itself, the query will automatically be applied to the layer view instead.

Returns
Promise<LayerFeatureSet[]>

A promise that resolves to an array of LayerFeatureSet, which includes the layer and the resulting features for that layer.

getSelection

Method
Signature
getSelection (target: GraphicsLayer): Graphic[] | undefined

Gets the active selection for the provided layer. If the layer is not part of the sources or has no active selection, this method returns undefined. Otherwise, it returns an array of selected features, which can be either Graphic[] or ObjectId[] depending on the layer's capabilities. To retrieve the full graphic representations of selected features from a layer that supports only object ID selection, use the getSelectedFeatures method. This method queries the layer using the selected object IDs and returns the corresponding feature graphics.

Parameters
ParameterTypeDescriptionRequired
target

The selectable layer that provides the selected features. This must be a layer with graphics in the sources.

Returns
Graphic[] | undefined

Returns an array of Graphics representing the selected features.

getSelection

Method
Signature
getSelection (target: SelectableLayerWithObjectIds): ObjectId[] | undefined
Parameters
ParameterTypeDescriptionRequired
target

The selectable layer that provides the selected features. This must be a layer with object IDs in the sources.

Returns
ObjectId[] | undefined

Returns an array of ObjectId's representing the selected features.

getSelection

Method
Signature
getSelection (target: SelectableLayer): SelectionIdentifier[] | undefined
Parameters
ParameterTypeDescriptionRequired
target

The selectable layer that provides the selected features.This must be a layer in the sources. It can be a layer with graphics or object IDs.

Returns
SelectionIdentifier[] | undefined

Returns an array of selected features represented as either Graphic[] or ObjectId[] dependent upon the layer's capabilities.

hasEventListener

inherited Method
Signature
hasEventListener <Type extends EventNames<this>>(type: Type): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

Indicates whether there is an event listener on the instance that matches the provided event name.

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

Returns
boolean

Returns true if the class supports the input event.

on

inherited Method
Signature
on <Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

Registers an event handler on the instance. Call this method to hook an event with a listener.

Parameters
ParameterTypeDescriptionRequired
type
Type

An event or an array of events to listen for.

listener
EventedCallback<this["@eventTypes"][Type]>

The function to call when the event fires.

Returns
ResourceHandle

Returns an event handler with a remove() method that should be called to stop listening for the event(s).

PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.
Example
view.on("click", function(event){
// event is the event handle returned after the event fires.
console.log(event.mapPoint);
});

remove

Method
Signature
remove (layer: GraphicsLayer, selection: Graphic[]): void

Removes the provided features from the current selection for the provided layer.

Parameters
ParameterTypeDescriptionRequired
layer

The selectable layer from which to remove the selection. This must be a layer with graphics in the sources.

selection

An array of features, ie. Graphic[] to remove from the current selection.

Returns
void

remove

Method
Signature
remove (layer: SelectableLayerWithObjectIds, selection: ObjectId[] | Graphic[]): void
Parameters
ParameterTypeDescriptionRequired
layer

The selectable layer from which to remove the selection. This must be a layer with object IDs in the sources.

selection

An array of features, ie. ObjectId[] to remove from the current selection.

Returns
void

remove

Method
Signature
remove (layer: SelectableLayer, selection: SelectionIdentifier[]): void
Parameters
ParameterTypeDescriptionRequired
layer

The selectable layer from which to remove the selection. This must be a layer in the sources. It can be a layer with graphics or object IDs.

selection

An array of features, ie. Graphic[] or ObjectId[] to remove from the current selection.

Returns
void

replace

Method
Signature
replace (layer: GraphicsLayer, selection: Graphic[]): void

Replaces the current selection for the provided layer with the provided features.

Parameters
ParameterTypeDescriptionRequired
layer

The selectable layer for which to replace the selection. This must be a layer with graphics in the sources.

selection

An array of features, ie. Graphic[] to set as the current selection.

Returns
void

replace

Method
Signature
replace (layer: SelectableLayerWithObjectIds, selection: ObjectId[] | Graphic[]): void
Parameters
ParameterTypeDescriptionRequired
layer

The selectable layer for which to replace the selection. This must be a layer with object IDs in the sources.

selection

An array of features, ie. ObjectId[] to set as the current selection.

Returns
void

replace

Method
Signature
replace (layer: SelectableLayer, selection: SelectionIdentifier[]): void
Parameters
ParameterTypeDescriptionRequired
layer

The selectable layer for which to replace the selection. This must be a layer in the sources. It can be a layer with graphics or object IDs.

selection

An array of features, ie. Graphic[] or ObjectId[] to set as the current selection.

Returns
void

syncSources

Method
Signature
syncSources (): void

A convenience method to synchronize the sources with the layers and tables in the provided view. This is useful when layers or tables have been added or removed from the View. This method is not applicable if Map is not provided with the view.

See also
Returns
void
Example
// Add a layer to the view's map after the selection manager has already been created
// and synced with the existing layers.
// Then, call syncSources to update the selection manager with the new layer.
const selectionManager = new SelectionManager({
view: someView
});
someView.map.add(featureLayer);
selectionManager.syncSources();

toggle

Method
Signature
toggle (layer: GraphicsLayer, selection: Graphic[]): void

Toggles selection for the provided features within the provided layer's selection set. If a given feature is part of the current set it will be removed, otherwise it will be added. This method is designed to make it easy to toggle features in/out of the selected set in response to a query or UI event.

Parameters
ParameterTypeDescriptionRequired
layer

The selectable layer for which to toggle the selection. This must be a layer with graphics in the sources.

selection

An array of features, ie. Graphic[] to toggle within the current selection.

Returns
void

toggle

Method
Signature
toggle (layer: SelectableLayerWithObjectIds, selection: ObjectId[] | Graphic[]): void
Parameters
ParameterTypeDescriptionRequired
layer

The selectable layer for which to toggle the selection. This must be a layer with object IDs in the sources.

selection

An array of features, ie. ObjectId[] to toggle within the current selection.

Returns
void

toggle

Method
Signature
toggle (layer: SelectableLayer, selection: SelectionIdentifier[]): void
Parameters
ParameterTypeDescriptionRequired
layer

The selectable layer for which to toggle the selection. This must be a layer in the sources. It can be a layer with graphics or object IDs.

selection

An array of features, ie. Graphic[] or ObjectId[] to toggle within the current selection.

Returns
void

Events

NameType
CustomEvent<{ view: View | null | undefined; changes: LayerSelectionChange[]; }>

selection-change

Event
selection-change: CustomEvent<{ view: View | null | undefined; changes: LayerSelectionChange[]; }>
bubbles composed cancelable

Type definitions