# MapEvents

The events a map adapter emits, with their payloads.

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

## Signature

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

## Properties

### basemapUnavailable

```ts
basemapUnavailable: BasemapDefinition;
```

The basemap's own tiles all failed and none loaded, counted from its style
loading to the moment the map settled: its provider is down or
unreachable (an expired certificate looks like this too). Data layers do
not count. It carries the basemap whose style those tiles belong to, so a
report that arrives before a mount has resolved, or after another basemap
was asked for, still names the right one. It is reported at most once each
time a basemap's style loads, and never once any tile of it has loaded.

### click

```ts
click: MapClickEvent;
```

A click or tap on the map, other than one that ends a press on an edit handle.

### fatalError

```ts
fatalError: MapEngineError;
```

The engine stopped working after it had loaded (for example its worker
failed), so the map can no longer draw. The error's reason is
`stopped`. A failed tile or source is a `tileError` instead, and a
failed `mount` or `setBasemap` rejects its promise.

### featureTap

```ts
featureTap: MapFeatureTap;
```

A tap or click landed on a point, polygon or line of a feed layer. Fires
before the `click` for the same tap, with the topmost feature within a
finger's reach and every feature found there.

### handleDrag

```ts
handleDrag: MapHandleDrag;
```

A press on an edit handle moved, or started or ended. See [`MapHandleDrag`](https://docs.mapcairn.com/api/core/MapHandleDrag.md).

### handleHover

```ts
handleHover: string | null;
```

A mouse or pen moved over an edit handle (its id) or off every handle
(null). Not emitted for touch, which has no hover.

### load

```ts
load: undefined;
```

The current basemap's style and its own sources are in. Data layers are
not waited for, so their tiles may still be arriving.

### loading

```ts
loading: boolean;
```

True while the style or the basemap's own tiles are loading, false once
they are in. A data layer's tiles do not count, so a tile of one that never
answers cannot keep the map busy.

### move

```ts
move: ViewState;
```

The view is changing (fires continuously while moving).

### moveEnd

```ts
moveEnd: ViewState;
```

The view stopped changing.

### rotate

```ts
rotate: ViewState;
```

The bearing changed.

### tileError

```ts
tileError: undefined;
```

A tile or style request failed. The map still works.

### tileLayerRecovered

```ts
tileLayerRecovered: MapTileLayerRecovered;
```

A tile of a tile data layer loaded after the layer reported
`tileLayerSlow` or `tileLayerUnavailable` for the same tiles, for example
once a transient failure has passed and the person pans. It is emitted once
for each drawing that reported, when the first tile loads, however many
of the two it reported, and never for a layer that has not
reported, so a layer that always loaded says nothing. "Each report" is per
drawing: setting the layer to new tiles starts the count again, and so
does the map drawing it again with the same tiles (a basemap swap), which keeps the report the ui is
still showing so the first tile after the redraw ends it. A change of opacity alone draws
nothing again and changes nothing.

### tileLayerSlow

```ts
tileLayerSlow: MapTileLayerSlow;
```

A tile data layer has had tiles asked for, and none of its tiles has
loaded, for longer than the adapter's wait: the provider is slow or not
answering. It does not wait for the map to settle, which a tile that never
answers prevents. It is emitted at most once for each drawing of the
layer (see `tileLayerRecovered` for what a drawing is), only while a tile it asked for is still outstanding, and never
once any tile of the layer has loaded. A layer that goes on to report
`tileLayerUnavailable` for the same tiles (the tile that held it up was
answered with a failure, and the map settled) has both, slow first; the
ui shows the later. The layer's failures raise no general `tileError`.

### tileLayerUnavailable

```ts
tileLayerUnavailable: MapTileLayerUnavailable;
```

The tiles of a tile data layer all failed and none loaded, counted from
the moment the layer's tiles were last set (a new `tiles` template, or a
basemap swap drawing the layer again) to the moment the map settled: the
provider has none for what was asked, for example a date or time it has
not published, or is unreachable. It is reported at most once each time
the layer's tiles are set, and never once any tile of it has loaded. The
layer's failures raise no general `tileError`: this is the layer's own
report, so the ui can say what is wrong with that layer.

### userZoom

```ts
userZoom: ViewState;
```

The person zoomed with a gesture the engine handles itself: a wheel or
trackpad, a pinch, or a double-click or double-tap. Fires as the zoom
changes, with the new view, as well as `zoom`. A change made in code
(`setView`, `zoomIn`, `fitBounds`, `setBasemap` and the rest) never
fires it.

### zoom

```ts
zoom: ViewState;
```

The normalised zoom changed.

## See also

- [`BasemapDefinition`](https://docs.mapcairn.com/api/core/BasemapDefinition.md)
- [`MapClickEvent`](https://docs.mapcairn.com/api/core/MapClickEvent.md)
- [`MapEngineError`](https://docs.mapcairn.com/api/core/MapEngineError.md)
- [`MapFeatureTap`](https://docs.mapcairn.com/api/core/MapFeatureTap.md)
- [`MapHandleDrag`](https://docs.mapcairn.com/api/core/MapHandleDrag.md)
- [`ViewState`](https://docs.mapcairn.com/api/core/ViewState.md)
- [`MapTileLayerRecovered`](https://docs.mapcairn.com/api/core/MapTileLayerRecovered.md)
- [`MapTileLayerSlow`](https://docs.mapcairn.com/api/core/MapTileLayerSlow.md)
- [`MapTileLayerUnavailable`](https://docs.mapcairn.com/api/core/MapTileLayerUnavailable.md)

Source: [packages/core/src/ports/map.ts:444](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/ports/map.ts#L444)
