# MapContextValue

What [`useMap`](https://docs.mapcairn.com/api/map/useMap.md) returns: the live map, as seen by overlays and chrome.

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

## Signature

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

## Properties

### adapter

```ts
readonly adapter: MapAdapter | null;
```

The mounted adapter, or null while the engine is starting, after it failed
and during server rendering. Overlays draw nothing while it is null.

### canZoomIn

```ts
readonly canZoomIn: boolean;
```

False once the zoom is at `maxZoom`.

### canZoomOut

```ts
readonly canZoomOut: boolean;
```

False once the zoom is at `minZoom`.

### error

```ts
readonly error: MapEngineError | null;
```

Why the engine could not start, or why it stopped after it loaded
(reason `stopped`), or null. The app decides the fallback.

### focusMap

```ts
readonly focusMap: () => void;
```

Moves keyboard focus to the map region without scrolling.

### hostElement

```ts
readonly hostElement: HTMLElement | null;
```

The element the engine is mounted in, or null with no mounted engine.
A new element replaces it when a failed mount is retried.

### label

```ts
readonly label?: string;
```

The name the host gave this map (`MapView`'s `label`), or undefined. The
interface adds it to the names of its landmarks.

### loading

```ts
readonly loading: boolean;
```

True while the engine starts, the basemap changes or tiles load.

### maxZoom

```ts
readonly maxZoom: number;
```

The highest normalised zoom the active basemap allows.

### minZoom

```ts
readonly minZoom: number;
```

Normalised zoom limits of the active basemap.

### onUserZoom

```ts
readonly onUserZoom: (listener: () => void) => () => void;
```

Calls `listener` each time the person zooms the map itself: with the
zoom keys on the map region, or with a gesture the engine handles (a
wheel, a pinch, a double-click). Zooms made in code, such as restoring a
permalink or applying a basemap's limits, never call it. Returns the
function that unsubscribes.

### projection

```ts
readonly projection: MapProjection;
```

The shape the map is drawn as, from the settings: flat or a globe.
Overlays read it to curve long lines and hide the far side.

### retry

```ts
readonly retry: () => void;
```

Re-applies the active basemap after a tile error. After an engine error it
mounts the engine again instead.

### tileError

```ts
readonly tileError: boolean;
```

True after a tile or style request failed, until a later load succeeds without one.

### view

```ts
readonly view: ViewState;
```

The current view, updated at most once per animation frame while the map
moves, zooms or rotates, so overlays re-project without thrashing.

## See also

- [`MapAdapter`](https://docs.mapcairn.com/api/core/MapAdapter.md)
- [`MapEngineError`](https://docs.mapcairn.com/api/core/MapEngineError.md)
- [`MapProjection`](https://docs.mapcairn.com/api/core/MapProjection.md)
- [`ViewState`](https://docs.mapcairn.com/api/core/ViewState.md)

Source: [packages/map/src/host/MapContext.ts:12](https://github.com/MapCairn/mapcairn/blob/main/packages/map/src/host/MapContext.ts#L12)
