> 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/events-reference.md).

# Events reference

Every listener on the Felt controller follows the same pattern: you pass a `handler` (and sometimes an `options` object scoping the listener to a specific entity), and the call returns an unsubscribe function.

```typescript
const unsubscribe = felt.onLayerChange({
  options: { id: "layer-1" },
  handler: ({ layer }) => console.log(layer.bounds),
});

// ...later, when you no longer need the listener
unsubscribe();
```

Always call the unsubscribe function when your UI unmounts or the listener is no longer needed.

## Viewport and map state

| Listener            | Scoping options | Handler receives                                                                                             |
| ------------------- | --------------- | ------------------------------------------------------------------------------------------------------------ |
| `onViewportMove`    | —               | `ViewportState` — fires continuously during movement, including during animations and inertia.               |
| `onViewportMoveEnd` | —               | `ViewportState` — fires once when dragging, zooming, animations, and inertia have finished.                  |
| `onMapIdle`         | —               | Nothing. Fires when the map is fully idle: no transitions, no interaction, all tiles loaded, fades complete. |
| `onBasemapChange`   | —               | `Basemap` — the new basemap.                                                                                 |

## Annotations (elements)

| Listener               | Scoping options | Handler receives                                                                                                                                                          |
| ---------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `onElementCreate`      | —               | `{ element: Element \| null, isBeingCreated: boolean }` — fires repeatedly while the user draws (`isBeingCreated: true`), then a final time with `isBeingCreated: false`. |
| `onElementCreateEnd`   | —               | `{ element: Element }` — fires once, when creation is finished.                                                                                                           |
| `onElementChange`      | `{ id }`        | `{ element: Element \| null, isBeingCreated: boolean }` — `element` is `null` if it was removed.                                                                          |
| `onElementDelete`      | `{ id }`        | Nothing.                                                                                                                                                                  |
| `onElementGroupChange` | `{ id }`        | `{ elementGroup: ElementGroup \| null }`                                                                                                                                  |

## Layers and legends

| Listener                  | Scoping options   | Handler receives                                                                                                                                         |
| ------------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `onLayerChange`           | `{ id }`          | `{ layer: Layer \| null }`                                                                                                                               |
| `onLayerGroupChange`      | `{ id }`          | `{ layerGroup: LayerGroup \| null }`                                                                                                                     |
| `onLegendItemChange`      | `{ id, layerId }` | `{ legendItem: LegendItem \| null }`                                                                                                                     |
| `onLayerFiltersChange`    | `{ layerId }`     | `LayerFilters` — the bare filters object (`{ style, components, ephemeral, combined }`), with no wrapper. See [Layer filters](/js-sdk/layer-filters.md). |
| `onLayerBoundariesChange` | `{ layerId }`     | `LayerBoundaries \| null`                                                                                                                                |

## Pointer and selection

| Listener            | Scoping options | Handler receives                                                                                                                                             |
| ------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `onPointerClick`    | —               | `MapInteractionEvent` — `{ coordinate, point, features, rasterValues }`. `features` and `rasterValues` are arrays (empty when nothing is under the pointer). |
| `onPointerMove`     | —               | `MapInteractionEvent`                                                                                                                                        |
| `onSelectionChange` | —               | `{ selection: EntityNode[] }` — see [Working with selection](/js-sdk/working-with-selection.md).                                                             |

## Tools

| Listener               | Scoping options | Handler receives                                                                                             |
| ---------------------- | --------------- | ------------------------------------------------------------------------------------------------------------ |
| `onToolChange`         | —               | `ToolType \| null` — the newly selected tool, or `null` when no tool is active.                              |
| `onToolSettingsChange` | —               | `ToolSettingsChangeEvent` — a discriminated union: check the `tool` field to narrow to that tool's settings. |

For payload type details, follow each method's entry in the [API reference](https://developers.felt.com/js-sdk-api-reference).


---

# 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/events-reference.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.
