import SelectionManager from "@arcgis/core/views/SelectionManager.js";const SelectionManager = await $arcgis.import("@arcgis/core/views/SelectionManager.js");- Inheritance:
- SelectionManager→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 5.0
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
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| properties | | |
Properties
| Property | Type | Class |
|---|---|---|
count readonly | | |
declaredClass readonly inherited | ||
hasSelection readonly | | |
| | ||
| | ||
selections readonly | | |
| | ||
updating readonly | | |
| |
hasSelection
- Type
- boolean
Returns true if at least one source has an active selection.
highlightEnabled
- Type
- boolean
Indicates whether to display a visual representation of the selection with a highlight.
- Default value
- true
highlightName
- Type
- string
The highlights name to use when specifying a set of highlight options.
- Default value
- "default"
selections
- Type
- LayerSelection[]
sources
- 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
- Type
- boolean
Indicates whether the selection manager is currently updating the view's visualization of selections.
- Default value
- false
Methods
| Method | Signature | Class |
|---|---|---|
add(layer: GraphicsLayer, selection: Graphic[]): void | | |
add(layer: SelectableLayerWithObjectIds, selection: ObjectId[] | Graphic[]): void | | |
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
- Signature
-
add (layer: GraphicsLayer, selection: Graphic[]): void
Adds features to the current selection. It does not replace the existing selection.
add
- Signature
-
add (layer: SelectableLayer, selection: SelectionIdentifier[]): void
Adds features to the current selection. It does not replace the existing selection.
emit
- Signature
-
emit <Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
- Type parameters
- <Type extends EventNames<this>>
- 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.
getSelectedFeatures
- 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
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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 | |
- Returns
- Promise<LayerFeatureSet[]>
A promise that resolves to an array of LayerFeatureSet, which includes the layer and the resulting features for that layer.
getSelection
- 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
| Parameter | Type | Description | Required |
|---|---|---|---|
| target | The selectable layer that provides the selected features. This must be a layer with graphics in the sources. | |
getSelection
- Signature
-
getSelection (target: SelectableLayerWithObjectIds): ObjectId[] | undefined
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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
- Signature
-
getSelection (target: SelectableLayer): SelectionIdentifier[] | undefined
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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
- Signature
-
hasEventListener <Type extends EventNames<this>>(type: Type): boolean
- Type parameters
- <Type extends EventNames<this>>
Indicates whether there is an event listener on the instance that matches the provided event name.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| type | Type | The name of the event. | |
- Returns
- boolean
Returns true if the class supports the input event.
on
- Signature
-
on <Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
- Type parameters
- <Type extends EventNames<this>>
Registers an event handler on the instance. Call this method to hook an event with a listener.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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).Property Type Description remove Function When 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
- Signature
-
remove (layer: GraphicsLayer, selection: Graphic[]): void
Removes the provided features from the current selection for the provided layer.
remove
- Signature
-
remove (layer: SelectableLayerWithObjectIds, selection: ObjectId[] | Graphic[]): void
remove
- Signature
-
remove (layer: SelectableLayer, selection: SelectionIdentifier[]): void
replace
- Signature
-
replace (layer: GraphicsLayer, selection: Graphic[]): void
Replaces the current selection for the provided layer with the provided features.
replace
- Signature
-
replace (layer: SelectableLayerWithObjectIds, selection: ObjectId[] | Graphic[]): void
replace
- Signature
-
replace (layer: SelectableLayer, selection: SelectionIdentifier[]): void
syncSources
- 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
- 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.
toggle
- Signature
-
toggle (layer: SelectableLayerWithObjectIds, selection: ObjectId[] | Graphic[]): void
toggle
- Signature
-
toggle (layer: SelectableLayer, selection: SelectionIdentifier[]): void
Events
| Name | Type |
|---|---|
| CustomEvent<{
view: View | null | undefined;
changes: LayerSelectionChange[];
}> |
selection-change
selection-change: CustomEvent<{
view: View | null | undefined;
changes: LayerSelectionChange[];
}>