# LayerSource

Loads a feed layer's features, on request a feature's detail shapes, and
what a tile layer's service says is at a tap. One source serves every
definition: it reads the URL, the decoder and the filter from the
definition, so a new layer needs no new source.

This is an interface exported by `@mapcairn/core`, checked against version 0.2.0.

## Signature

```ts
import type { LayerSource } from "@mapcairn/core";
 
interface LayerSource
```

## Methods

### identify

```ts
identify(request: LayerIdentifyRequest): Promise<readonly LayerFeature[]>;
```

Asks a tile layer's service what is at a tapped place. It resolves to an empty list, not an error, when nothing is there.

- `request` (`LayerIdentifyRequest`)

### load

```ts
load(request: LayerLoadRequest): Promise<readonly LayerFeature[]>;
```

Loads a feed, query or heatmap layer's features.

- `request` (`LayerLoadRequest`)

### loadDetail

```ts
loadDetail(request: LayerDetailRequest): Promise<readonly LayerFeature[]>;
```

Loads the detail shapes of one feature, such as an affected area.

- `request` (`LayerDetailRequest`)

## Remarks

`load` and `loadDetail` reject only with a `LayerError`:
 `network` when the request failed, `invalid` when the response could not
 be decoded or is larger than the source's limit on the size of an answer,
 `empty` when it decoded to no features, and `aborted` when the signal fired
 first.

`identify` rejects only with a `LayerError` too, but never with `empty`:
 nothing found is the common answer, so it resolves to an empty list.
 `network` includes a service that answered with an error status, which
 until an `unauthorised` kind exists includes 401 and 403. `invalid` is a
 URL that cannot be built or is not `https` (see `identifyRequestUrl`),
 an answer that is not a document the decoder reads, and an answer larger
 than the source's limit. A source keeps nothing an `identify` was answered
 with: every tap asks again.

The size of an answer belongs to the source: one that reads from a network
 applies a limit of its own to every `load`, `loadDetail` and `identify`
 answer, stops reading at the limit and refuses a larger answer as
 `invalid`, so a provider cannot make the page hold an unbounded body.

## See also

- [`LayerIdentifyRequest`](https://docs.mapcairn.com/api/core/LayerIdentifyRequest.md)
- [`LayerFeature`](https://docs.mapcairn.com/api/core/LayerFeature.md)
- [`LayerLoadRequest`](https://docs.mapcairn.com/api/core/LayerLoadRequest.md)
- [`LayerDetailRequest`](https://docs.mapcairn.com/api/core/LayerDetailRequest.md)

Source: [packages/core/src/ports/layers.ts:130](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/ports/layers.ts#L130)
