> For the complete documentation index, see [llms.txt](https://developers.felt.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.felt.com/js-sdk-api-reference/selection/selectioncontroller.md).

# SelectionController

***

The Selection controller allows you to listen for changes to the selection on the map.

## Extended by

* [`FeltController`](/js-sdk-api-reference/main/feltcontroller.md)

## Methods

### getSelection()

> **getSelection**(): `Promise`<[`EntityNode`](/js-sdk-api-reference/selection/entitynode.md)\[]>

Gets the current selection as a list of entity identifiers.

Use this method to retrieve the current selection state, which can include features, elements, or both types of entities.

#### Returns

`Promise`<[`EntityNode`](/js-sdk-api-reference/selection/entitynode.md)\[]>

A promise that resolves to an array of selected entity nodes.

#### Example

```typescript
const selection = await felt.getSelection();
```

***

### selectFeature()

> **selectFeature**(`params`: [`FeatureSelection`](/js-sdk-api-reference/selection/featureselection.md)): `Promise`<`void`>

Selects a feature on a layer. This will show the feature's popup, modal or sidebar (if configured) and highlight the feature.

Use this method to programmatically select features, which can be useful for highlighting specific data points or triggering feature-specific UI.

#### Parameters

| Parameter | Type                                                                      |
| --------- | ------------------------------------------------------------------------- |
| `params`  | [`FeatureSelection`](/js-sdk-api-reference/selection/featureselection.md) |

#### Returns

`Promise`<`void`>

A promise that resolves when the feature is selected.

#### Example

```typescript
felt.selectFeature({
  id: 123,
  layerId: "my-layer",
  showPopup: true,
  fitViewport: { maxZoom: 15 },
});
```

***

### clearSelection()

> **clearSelection**(`params`?: { `features`: `boolean`; `elements`: `boolean`; }): `Promise`<`void`>

Clears the current selection (elements, features or both).

Use this method to programmatically clear the current selection, which can be useful for resetting the map state or preparing for new selections.

#### Parameters

| Parameter          | Type                                              | Description                                                                                                 |
| ------------------ | ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| `params`?          | { `features`: `boolean`; `elements`: `boolean`; } | The parameters to clear the selection. If this is not provided, both features and elements will be cleared. |
| `params.features`? | `boolean`                                         | Whether to clear the features from the selection.                                                           |
| `params.elements`? | `boolean`                                         | Whether to clear the elements from the selection.                                                           |

#### Returns

`Promise`<`void`>

A promise that resolves when the selection is cleared.

#### Example

```typescript

// Removes all features and elements from the selection
felt.clearSelection();

// Removes only features from the selection
felt.clearSelection({ features: true });

// Removes only elements from the selection
felt.clearSelection({ elements: true });
```

#### Default

```typescript
{ features: true, elements: true }
```

## Events

### onSelectionChange()

> **onSelectionChange**(`params`: { `handler`: (`change`: { `selection`: [`EntityNode`](/js-sdk-api-reference/selection/entitynode.md)\[]; }) => `void`; }): `VoidFunction`

Adds a listener for when the selection changes.

Use this to react to selection changes, such as updating your UI to reflect what is currently selected on the map.

#### Parameters

| Parameter        | Type                                                                                                                     |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `params`         | { `handler`: (`change`: { `selection`: [`EntityNode`](/js-sdk-api-reference/selection/entitynode.md)\[]; }) => `void`; } |
| `params.handler` | (`change`: { `selection`: [`EntityNode`](/js-sdk-api-reference/selection/entitynode.md)\[]; }) => `void`                 |

#### Returns

`VoidFunction`

A function to unsubscribe from the listener.

#### Example

```typescript
const unsubscribe = felt.onSelectionChange({
  handler: ({selection}) => console.log(selection),
});

// later on...
unsubscribe();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.felt.com/js-sdk-api-reference/selection/selectioncontroller.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
