For the complete documentation index, see llms.txt. This page is also available as Markdown.

General concepts

This guide covers the mental model and the common patterns used throughout the Felt SDK. Understanding these once makes every other page predictable.

The Felt controller

Everything you do with the SDK goes through a controller object — named felt in all the examples in these docs. How you get it depends on where your code runs:

  • Embeds — your code runs in your page, and the map lives in an iframe. Felt.embed(container, mapId, options) creates the iframe and returns a controller for it. You can also use Felt.connect(iframe.contentWindow) to attach a controller to a Felt iframe you've already placed on the page. See Controlling maps and Embed options.

  • Extensions — your code runs inside the Felt app, and receives a ready-made controller: no embedding required. See the extensions documentation.

The controller communicates with the map via message passing, which is why every read is asynchronous (see promises below). The same controller API is available in both contexts.

import { Felt } from "@feltmaps/js-sdk";

const felt = await Felt.embed(
  document.getElementById("container"),
  FELT_MAP_ID,
);

Session-only vs persisted changes

A crucial rule for building on the SDK: changes made via the SDK are visible only to the current session — they are not saved to the map. This applies to:

This makes the SDK safe for building per-visitor experiences on shared maps: ten visitors can each see their own filters and drawings without affecting each other or the underlying map. To make persistent changes to a map, use the REST API.

Use of promises

All methods in the Felt SDK are asynchronous and return Promises — writes as well as reads. This means you'll need to use await or .then() when calling them:

Getting entities

The SDK follows a consistent pattern for getting entities. For each entity type, there are usually two getters:

  1. A singular getter for retrieving one entity by ID:

  1. A plural getter that accepts constraints for retrieving multiple entities:

The plural getters also allow you to pass no constraints, in which case they'll return all entities of that type:

Getters can return null

Singular getters return null when the entity doesn't exist, and plural getters can contain null entries — always check before using the result:

Batch your reads

When you need multiple entities, use the plural methods with constraints rather than making multiple individual calls:

Change listeners

Each entity type has a corresponding change listener method following the pattern on{EntityType}Change:

There are also various other setters and getters in the Felt SDK that follow this convention as much as possible. For example, selection:

And layer filters — note that this particular listener receives the filters value directly, with no wrapper object:

For the full list of listeners and their payloads, see the Events reference.

Cleanup functions

All change listeners return an unsubscribe function that should be called when you no longer need the listener:

This is particularly important in frameworks like React where you should clean up listeners when components unmount:

Handler and options structure

Change listeners always take a single object parameter containing both options and handler. This structure makes it easier to add new options in the future without breaking existing code:

Entity nodes

When dealing with mixed collections of entities (like in selection events), each entity is wrapped in an EntityNode object that includes type information:

Last updated

Was this helpful?