# Styling layers

## Understanding layer styles

A layer's style is defined in a JSON-based called [the Felt Style Language](/felt-style-language/getting-started.md), or FSL for short. Editors can view the current style of a layer inside a Felt map by clicking on `Actions > Edit styles` in a layer's overflow menu (three dots).

Here is an example of a simple visualization, expressed in FSL:

```json
{
  "config": {"labelAttribute": ["type"]},
  "legend": {},
  "paint": {
    "color": "blue",
    "opacity": 0.9,
    "size": 30,
    "strokeColor": "auto",
    "strokeWidth": 1
  },
  "type": "simple",
  "version": "2.1"
}
```

## Fetching a layer's current style

A layer's FSL can be retrieved by performing a simple `GET` request to a layer's endpoint:

{% tabs %}
{% tab title="curl" %}

```bash
# Your API token should look like this:
# FELT_API_TOKEN="felt_pat_ABCDEFUDQPAGGNBmX40YNhkCRvvLI3f8/BCwD/g8"
FELT_API_TOKEN="<YOUR_API_TOKEN>"
MAP_ID="<YOUR_MAP_ID>"
LAYER_ID="<YOUR_LAYER_ID>"

curl -L \
  -H "Authorization: Bearer ${FELT_API_TOKEN}" \
  "https://felt.com/api/v2/maps/${MAP_ID}/layers/${LAYER_ID}"
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

# Your API token should look like this:
# api_token = "felt_pat_ABCDEFUDQPAGGNBmX40YNhkCRvvLI3f8/BCwD/g8"
api_token = "<YOUR_API_TOKEN>"
map_id = "<YOUR_MAP_ID>"
layer_id = "<YOUR_LAYER_ID>"

r = requests.get(
  f"http://felt.com/api/v2/maps/{map_id}/layers/{layer_id}",
  headers={"Authorization": f"Bearer {api_token}"}
)
assert r.ok
print(r.json())
```

{% endtab %}

{% tab title="felt-python" %}

```python
import os

from felt_python import get_layer_details

# Setting your API token as an env variable can save
# you from repeating it in every function call
os.environ["FELT_API_TOKEN"] = "<YOUR_API_TOKEN>"

map_id = "<YOUR_MAP_ID>"
layer_id = "<YOUR_LAYER_ID>"

layer_details = get_layer_details(map_id, layer_id)
```

{% endtab %}
{% endtabs %}

## Updating an existing layer's style

To update a layer's style, we can send a `POST` request with the new FSL to the same layer's `/update_style` endpoint.

{% tabs %}
{% tab title="curl" %}

```bash
curl -L \
  -X POST \
  "https://felt.com/api/v2/maps/${MAP_ID}/layers/${LAYER_ID}/update_style" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${FELT_API_TOKEN}" \
  --data '{"style": {"paint": {"color": "green", "opacity": 0.9, "size": 30, "strokeColor": "auto", "strokeWidth": 1}, "legend": {}, "type": "simple", "version": "2.1"}}'
```

{% endtab %}

{% tab title="Python" %}

```python
new_fsl = {
  "paint": {
    "color": "green",
    "opacity": 0.9,
    "size": 30,
    "strokeColor": "auto",
    "strokeWidth": 1
  },
  "legend": {},
  "type": "simple",
  "version": "2.1"
}

r = requests.post(
  f"http://felt.com/api/v2/maps/{map_id}/layers/{layer_id}/update_style",
  json={"style": new_fsl},
  headers={"Authorization": f"Bearer {api_token}"}
)
assert r.ok
print(r.json())
```

{% endtab %}

{% tab title="felt-python" %}

```python
from felt_python import update_layer_style

new_fsl = {
  "paint": {
    "color": "green",
    "opacity": 0.9,
    "size": 30,
    "strokeColor": "auto",
    "strokeWidth": 1
  },
  "legend": {},
  "type": "simple",
  "version": "2.1"
}

update_layer_style(
    map_id=map_id,
    layer_id=layer_id,
    style=new_fsl,
)
```

{% endtab %}
{% endtabs %}

## FSL examples

You can find examples of FSL for different visualization types in [the Felt Style Language section](/felt-style-language/getting-started.md) of these docs:

* [Simple visualizations](/felt-style-language/types-of-visualizations/simple-visualizations.md): same color and size for all features (vector) or pixels (raster).
* [Categorical visualizations](/felt-style-language/types-of-visualizations/categorical-visualizations.md): different color per feature or pixel, based on a categorical attribute
* [Numeric visualizations](/felt-style-language/types-of-visualizations/numeric-visualizations-color-and-size.md): different color or size per feature or pixel, based on a numeric attribute.
* [Heatmaps](/felt-style-language/types-of-visualizations/heatmaps.md): a density-based visualization style, for vector point layers.
* [Hillshade](/felt-style-language/types-of-visualizations/hillshade.md): a special kind of visualization for raster elevation layers.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.felt.com/rest-api/styling-layers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
