# MapHandle

A map that was drawn in an element.

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

## Signature

```ts
import type { MapHandle } from "@mapcairn/map";
 
interface MapHandle
```

## Properties

### layersState

```ts
readonly layersState: MapStore<MapLayersState>;
```

The layers the map offers and whether each is on, as a store: read it with
`getState()` and listen with `subscribe(listener)`. It is `loading`, with
no layers, until the map has drawn its interface and after `destroy()`.
In releases after `0.2.0`, not in `0.2.0` or any earlier release.

### ready

```ts
readonly ready: Promise<void>;
```

Resolves when the engine is drawing. Rejects with a `MapEngineError` when it cannot start, or a `MountMapError` of kind `destroyed`.

## Methods

### chooseBasemap

```ts
chooseBasemap(id: string): void;
```

Picks a basemap as the person does in Map options: the choice is saved, and
written to the shared link, once the map has loaded it, and a basemap whose
provider proves to be down is undone. `update({ basemap })` is the page's
own choice and saves nothing. Does nothing after `destroy()`. In releases
after `0.2.0`, not in `0.2.0` or any earlier release.

- `id` (`string`)

### destroy

```ts
destroy(): void;
```

Removes the map and everything it added to the page. Safe to call again.

### getView

```ts
getView(): ViewState;
```

The view the map shows, or last showed after `destroy()`.

### on

```ts
on<K extends keyof MapHandleEvents>(type: K, listener: (event: MapHandleEvents[K]) => void): () => void;
```

Listens for an event and returns the function that stops listening.

- `type` (`K`)
- `listener` (`(event: MapHandleEvents[K]) => void`)

### setLayerEnabled

```ts
setLayerEnabled(id: string, enabled: boolean): void;
```

Turns a layer on or off, as its switch does. An id the map does not offer is
ignored, and so is a call before the interface has drawn and after
`destroy()`. In releases after `0.2.0`, not in `0.2.0` or any earlier
release.

- `id` (`string`)
- `enabled` (`boolean`)

### setView

```ts
setView(view: Partial<ViewState>, options?: SetViewOptions): void;
```

Moves the map. Does nothing after `destroy()`.

- `view` (`Partial<ViewState>`)
- `options?` (`SetViewOptions`)

### showMeasurement

```ts
showMeasurement(mode: MeasureMode, points: readonly LatLng[]): void;
```

Opens the measure tool showing these points in this mode, replacing the
mode and points of a measurement that is open. No points shows an empty
measurement. The input is checked first, so a bad mode or point is an
error even when the page did not name the `measure` tool. Then it does
nothing when the page did not name that tool, before the interface has
drawn, and after `destroy()`. The points are copied. In releases after
`0.2.0`, not in `0.2.0` or any earlier release.

- `mode` (`MeasureMode`)
- `points` (`readonly LatLng[]`)

### showResult

```ts
showResult(result: Pick<SearchResult, "centre" | "bounds">): void;
```

Shows a search result as the search box does: the map fits the result's
`bounds` to at most zoom 16, or, for a result with no `bounds`, moves to its
`centre` at zoom 14. Only `centre` and `bounds` are read. It waits for the
map to draw, and does nothing after `destroy()`. In releases after `0.2.0`,
not in `0.2.0` or any earlier release.

- `result` (`Pick<SearchResult, "centre" | "bounds">`)

### update

```ts
update(update: MapUpdate): void;
```

Changes the basemap or the theme. Does nothing after `destroy()`.

- `update` (`MapUpdate`)

## See also

- [`ViewState`](https://docs.mapcairn.com/api/core/ViewState.md)
- [`MapStore`](https://docs.mapcairn.com/api/map/MapStore.md)
- [`MapLayersState`](https://docs.mapcairn.com/api/map/MapLayersState.md)
- [`MapHandleEvents`](https://docs.mapcairn.com/api/map/MapHandleEvents.md)
- [`SetViewOptions`](https://docs.mapcairn.com/api/map/SetViewOptions.md)
- [`MeasureMode`](https://docs.mapcairn.com/api/map/MeasureMode.md)
- [`LatLng`](https://docs.mapcairn.com/api/core/LatLng.md)
- [`SearchResult`](https://docs.mapcairn.com/api/core/SearchResult.md)
- [`MapUpdate`](https://docs.mapcairn.com/api/map/MapUpdate.md)

Source: [packages/map/src/element/types.ts:318](https://github.com/MapCairn/mapcairn/blob/main/packages/map/src/element/types.ts#L318)
