# `FeatureCollection`

A list of features, all with the same shape and properties types, as a map layer.

Use it to send many shapes to a map library in one response. For one shape, use [`Feature`](/docs/types/type-feature.md).

## Shape

| Field | Type | Required? |
|---|---|---|
| `features` | `List<`[`Feature`](/docs/types/type-feature.md)`<G, P>>` | Yes |

## Example

```jadpo
type LayerStop = Object {
    name: Text
}

var layer: FeatureCollection<Point, LayerStop> = FeatureCollection { features: [] }
assert layer.features == []
```

## Good to know

- Name both types when you use it: `FeatureCollection<Point, LayerStop>`.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it, so sort by one of its parts instead.

## In JSON

A GeoJSON object of its geometry and properties, in a request, a response or `json.write`:

```json
{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.1276,51.5072]},"properties":{"name":"Site A"}}]}
{"type":"FeatureCollection","features":[]}
```

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`FeatureCollection` is in the group Geospatial, and has been in Jadpo since 0.1.0.

### Text form

It has no single text form, so `text.from` and `text.parse` don't take it.

### How it is stored

It is stored in one column named for the field, of type `jsonb`. `{"type":"FeatureCollection","features":[]}` is stored as `'{"type":"FeatureCollection","features":[]}'::jsonb`.

### How it is shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.1276,51.5072]},"properties":{"name":"Site A"}}]}` | `""` |
| `{"type":"FeatureCollection","features":[]}` | `""` |

### Operations

It also takes `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
