LayersController
The Layers controller allows you to get information about the layers on the map, and make changes to their visibility.
Layers can be organised into groups, and their groups can also have their visibility toggled.
Extended by
Methods
getLayer()
getLayer(
id
:string
):Promise
<null
|Layer
>
Get a single layer from the map by its id.
Parameters
id
string
The id of the layer you want to get.
Returns
Promise
<null
| Layer
>
The requested layer.
Example
getLayers()
getLayers(
constraint
?:GetLayersConstraint
):Promise
<(null
|Layer
)[]>
Gets layers from the map, according to the constraints supplied. If no constraints are supplied, all layers will be returned.
Parameters
constraint
?
The constraints to apply to the layers returned from the map.
Returns
Promise
<(null
| Layer
)[]>
All layers on the map.
Remarks
The layers in the map, ordered by the order specified in Felt. This is not necessarily the order that they are drawn in, as Felt draws points above lines and lines above polygons, for instance.
Example
setLayerVisibility()
setLayerVisibility(
visibility
:SetVisibilityRequest
):Promise
<void
>
Hide or show layers with the given ids.
Parameters
visibility
Returns
Promise
<void
>
Example
setLayerStyle()
setLayerStyle(
params
: {id
:string
;style
:object
; }):Promise
<void
>
Set the style for a layer using FSL, the Felt Style Language.
Changes are only for this session, and not persisted. This is useful to make temporary changes to a layer's style, such as to highlight a particular layer or feature.
See the FSL documentation for details on how to read and write styles.
If the style you set is invalid, you will receive an error explaining the problem in the rejected promise value.
Parameters
params
{ id
: string
; style
: object
; }
-
params.id
string
The id of the layer to set the style for.
params.style
object
The style to set for the layer.
Returns
Promise
<void
>
Example
setLayerLegendVisibility()
setLayerLegendVisibility(
params
:SetVisibilityRequest
):Promise
<void
>
Hide or show layers with the given ids from the legend.
Parameters
params
Returns
Promise
<void
>
Example
createLayersFromGeoJson()
createLayersFromGeoJson(
params
:CreateLayersFromGeoJsonParams
):Promise
<null
| {layerGroup
:LayerGroup
;layers
:Layer
[]; }>
Adds layers to the map from file or URL sources.
Parameters
params
Returns
Promise
<null
| { layerGroup
: LayerGroup
; layers
: Layer
[]; }>
The layer groups that were created.
Remarks
This allows you to add temporary layers to the map that don't depend on any processing by Felt. This is useful for viewing data from external sources or remote files.
Example
updateLayer()
updateLayer(
params
:UpdateLayerParams
):Promise
<Layer
>
Update a layer by passing a subset of the layer's properties.
Note that not all properties can be updated, so check the UpdateLayerParams type to see which properties can be updated.
Parameters
params
Returns
Promise
<Layer
>
Example
deleteLayer()
deleteLayer(
id
:string
):Promise
<void
>
Delete a layer from the map by its id.
Parameters
id
string
Returns
Promise
<void
>
Remarks
This only works for layers created via the SDK createLayersFromGeoJson
method, not layers added via the Felt UI.
Example
getLayerGroup()
getLayerGroup(
id
:string
):Promise
<null
|LayerGroup
>
Get a layer group from the map by its id.
Parameters
id
string
Returns
Promise
<null
| LayerGroup
>
The requested layer group.
Example
getLayerGroups()
getLayerGroups(
constraint
?:GetLayerGroupsConstraint
):Promise
<(null
|LayerGroup
)[]>
Gets layer groups from the map, according to the constraints supplied. If no constraints are supplied, all layer groups will be returned in rendering order.
Parameters
constraint
?
The constraints to apply to the layer groups returned from the map.
Returns
Promise
<(null
| LayerGroup
)[]>
The requested layer groups.
Example
setLayerGroupVisibility()
setLayerGroupVisibility(
visibility
:SetVisibilityRequest
):Promise
<void
>
Hide or show layer groups with the given ids.
Parameters
visibility
Returns
Promise
<void
>
Example
setLayerGroupLegendVisibility()
setLayerGroupLegendVisibility(
params
:SetVisibilityRequest
):Promise
<void
>
Hide or show layer groups with the given ids from the legend.
Parameters
params
Returns
Promise
<void
>
Example
getLegendItem()
getLegendItem(
id
:LegendItemIdentifier
):Promise
<null
|LegendItem
>
Allows you to get the state of a single legend item.
Parameters
id
Returns
Promise
<null
| LegendItem
>
Example
getLegendItems()
getLegendItems(
constraint
?:LegendItemsConstraint
):Promise
<(null
|LegendItem
)[]>
Allows you to obtain the state of several legend items, by passing in constraints describing which legend items you want.
If you do not pass any constraints, you will receive all legend items.
Parameters
constraint
?
Returns
Promise
<(null
| LegendItem
)[]>
Example
setLegendItemVisibility()
setLegendItemVisibility(
visibility
: {show
:LegendItemIdentifier
[];hide
:LegendItemIdentifier
[]; }):Promise
<void
>
Hide or show legend items with the given identifiers.
Parameters
visibility
visibility.show
?
visibility.hide
?
Returns
Promise
<void
>
Example
getLayerFilters()
getLayerFilters(
layerId
:string
):Promise
<null
|LayerFilters
>
Get the filters for a layer.
Parameters
layerId
string
Returns
Promise
<null
| LayerFilters
>
Remarks
The return type gives you the filters split up into the various sources that make up the overall filters for a layer.
Example
setLayerFilters()
setLayerFilters(
params
: {layerId
:string
;filters
:Filters
;note
:string
; }):Promise
<void
>
Sets the ephemeral filters for a layer.
Parameters
params
-
params.layerId
string
The layer that you want to set the filters for.
params.filters
The filters to set for the layer. This will replace any ephemeral filters that are currently set for the layer.
params.note
?
string
A note to display on the layer legend when this filter is applied. When the note is shown, a reset button will also be shown, allowing the user to clear the filter.
Returns
Promise
<void
>
Example
getLayerBoundaries()
getLayerBoundaries(
layerId
:string
):Promise
<null
|LayerBoundaries
>
Get the spatial boundaries that are filtering a layer.
Parameters
layerId
string
Returns
Promise
<null
| LayerBoundaries
>
Remarks
The return type gives you the boundaries split up into the various sources that make up the overall boundary for a layer.
The combined boundary is the intersection of the other sources of boundaries.
Example
setLayerBoundary()
setLayerBoundary(
params
: {layerIds
:string
[];boundary
:null
|GeometryFilter
; }):Promise
<void
>
Set the `ephemeral` boundary for one or more layers.
Parameters
params
-
params.layerIds
string
[]
The ids of the layers to set the boundary for.
params.boundary
The boundary to set for the layer. Passing null
clears the ephemeral boundary for the layer.
Returns
Promise
<void
>
Example
getRenderedFeatures()
getRenderedFeatures(
params
?:GetRenderedFeaturesConstraint
):Promise
<LayerFeature
[]>
Get the features that are currently rendered on the map in the viewport.
Note that this is explicitly about the features that are rendered, which isn't necessarily a complete list of all the features in the viewport. This is because of the way features are tiled: at low zoom levels or high feature densities, many features are omitted from what is rendered on the screen.
Parameters
params
?
The constraints to apply to the features returned from the map.
Returns
Promise
<LayerFeature
[]>
Example
getFeature()
getFeature(
params
: {id
:string
|number
;layerId
:string
; }):Promise
<null
|LayerFeature
>
Get a feature from the map by its ID and layer ID.
The response is a LayerFeature object, which does not include the geometry of the feature.
You may want to use this when you don't need the geometry of a feature, but you know the ID of the feature you need.
Parameters
params
{ id
: string
| number
; layerId
: string
; }
params.id
string
| number
params.layerId
string
Returns
Promise
<null
| LayerFeature
>
Example
getFeatures()
getFeatures(
params
: {layerId
:string
;filters
:Filters
;sorting
:SortConfig
;boundary
:GeometryFilter
;search
:string
;pagination
:null
|string
; }):Promise
<{features
:LayerFeature
[];count
:number
;previousPage
:null
|string
;nextPage
:null
|string
; }>
Get a list of layer features.
Parameters
params
-
params.layerId
string
The ID of the layer to get features from.
params.filters
?
Filters to be applied. These filters will merge with layer's own filters.
params.sorting
?
Attribute to sort by.
params.boundary
?
The spatial boundary to be applied.
params.search
?
string
Search term to search by. Search is case-insensitive and looks for matches across all feature properties.
params.pagination
?
null
| string
Pagination token. It comes from either the previousPage
or nextPage
properties of the previous response.
Returns
Promise
<{ features
: LayerFeature
[]; count
: number
; previousPage
: null
| string
; nextPage
: null
| string
; }>
The response is an object which contains:
features
: list of LayerFeature objects, which does not include the geometry of the feature but it does include its bounding box.count
: the total number of features that match the query.previousPage
&nextPage
: The tokens to pass in thepagination
param to navigate between pages.
Remarks
This list is paginated in sets of 20 features for each page. In order to paginate
between pages, the response includes previousPage
and nextPage
that are tokens
that should be sent in the pagination
params for requesting sibling pages.
Text search is case-insensitive and looks for matches across all feature properties.
Example
getGeoJsonFeature()
getGeoJsonFeature(
params
: {id
:string
|number
;layerId
:string
; }):Promise
<null
|GeoJsonFeature
>
Get a feature in GeoJSON format from the map by its ID and layer ID.
The response is a GeoJSON Feature object with the complete geometry of the feature. Note that for some very large geometries, the response may take a long time to return, and may return a very large object.
Parameters
params
{ id
: string
| number
; layerId
: string
; }
params.id
string
| number
params.layerId
string
Returns
Promise
<null
| GeoJsonFeature
>
Example
getCategoryData()
getCategoryData(
params
:GetLayerCategoriesParams
):Promise
<GetLayerCategoriesGroup
[]>
Gets values from a layer grouped by a given attribute.
Parameters
params
Returns
Promise
<GetLayerCategoriesGroup
[]>
Remarks
Groups features in your layer by unique values in the specified attribute and calculates a value for each group. By default, this value is the count of features in each group.
You can apply filters in two ways:
At the top level (using
boundary
andfilters
), which affects both what categories are included and how values are calculatedIn the
values
configuration, which only affects the values but keeps all categories
This two-level filtering is particularly useful when you want to compare subsets of data while maintaining consistent categories. For example, you might want to show the distribution of all building types in a city, but only count buildings built after 2000 in each category.
Example
getHistogramData()
getHistogramData(
params
:GetLayerHistogramParams
):Promise
<GetLayerHistogramBin
[]>
Gets a histogram of values from a layer for a given attribute.
Parameters
params
Returns
Promise
<GetLayerHistogramBin
[]>
Remarks
Creates bins (ranges) for numeric data and counts how many features fall into each bin, or returns aggregated values for each bin.
You can control how the bins are created using the steps
parameter, choosing from
several methods like equal intervals, quantiles, or natural breaks (Jenks), or passing
in the step values directly if you know how you want to bin the data.
Like getCategoryData, you can apply filters in two ways:
At the top level (using
boundary
andfilters
), which affects both how the bins are calculated and what features are counted in each binIn the
values
configuration, which only affects what gets counted but keeps the bin ranges the same
This is particularly useful when you want to compare distributions while keeping consistent bin ranges. For example, you might want to compare the distribution of building heights in different years while using the same height ranges.
Example
getAggregates()
getAggregates<
T
>(params
:GetLayerCalculationParams
<T
>):Promise
<Record
<T
,null
|number
>>
Calculates a single aggregate value for a layer based on the provided configuration.
Type Parameters
T
extends "avg"
| "max"
| "min"
| "sum"
| "median"
| "count"
Parameters
params
Returns
Promise
<Record
<T
, null
| number
>>
Remarks
Performs statistical calculations on your data, like counting features or computing averages, sums, etc. You can focus your calculation on specific areas or subsets of your data using boundaries and filters.
When no aggregation is specified, it counts features. When an aggregation is provided, it performs that calculation (average, sum, etc.) on the specified attribute.
Example
getLayerSchema()
getLayerSchema(
layerId
:string
):Promise
<LayerSchema
>
Get the schema for a layer.
Parameters
layerId
string
Returns
Promise
<LayerSchema
>
Remarks
The schema describes the structure of the data in a layer, including the attributes that are available on the features in the layer.
This can be useful to build generic UIs that need to know the structure of the data in a layer, such as a dropdown to choose an attribute.
Example
Events
onLayerChange()
onLayerChange(
args
: {options
: {id
:string
; };handler
: (change
:LayerChangeCallbackParams
) =>void
; }):VoidFunction
Adds a listener for when a layer changes.
Parameters
args
-
args.options
{ id
: string
; }
-
args.options.id
string
The id of the layer to listen for changes to.
args.handler
The handler that is called when the layer changes.
Returns
VoidFunction
A function to unsubscribe from the listener
Example
onLayerGroupChange()
onLayerGroupChange(
args
: {options
: {id
:string
; };handler
: (change
:LayerGroupChangeCallbackParams
) =>void
; }):VoidFunction
Adds a listener for when a layer group changes.
Parameters
args
args.options
{ id
: string
; }
args.options.id
string
args.handler
Returns
VoidFunction
A function to unsubscribe from the listener
Example
onLegendItemChange()
onLegendItemChange(
args
: {options
:LegendItemIdentifier
;handler
: (change
:LegendItemChangeCallbackParams
) =>void
; }):VoidFunction
Adds a listener for when a legend item changes.
Parameters
args
args.options
args.handler
Returns
VoidFunction
A function to unsubscribe from the listener
Example
onLayerFiltersChange()
onLayerFiltersChange(
params
: {options
: {layerId
:string
; };handler
: (change
:LayerFilters
) =>void
; }):VoidFunction
Adds a listener for when a layer's filters change.
Parameters
params
params.options
{ layerId
: string
; }
params.options.layerId
string
params.handler
Returns
VoidFunction
A function to unsubscribe from the listener
Remarks
This event fires whenever any type of filter changes on the layer, including ephemeral filters set via the SDK, style-based filters, or filters set through the Felt UI via Components.
Example
onLayerBoundariesChange()
onLayerBoundariesChange(
params
: {options
: {layerId
:string
; };handler
: (boundaries
:null
|LayerBoundaries
) =>void
; }):VoidFunction
Adds a listener for when a layer's spatial boundaries change.
Parameters
params
-
params.options
{ layerId
: string
; }
-
params.options.layerId
string
The id of the layer to listen for boundary changes on.
params.handler
A function that is called when the boundaries change.
Returns
VoidFunction
A function to unsubscribe from the listener
Remarks
This event fires whenever any type of spatial boundary changes on the layer, including ephemeral boundaries set via the SDK or boundaries set through the Felt UI via Spatial filter components.
Example
Last updated
Was this helpful?