# MapViewProps

Props for [`MapView`](https://docs.mapcairn.com/api/map/MapView.md).

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

## Signature

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

## Properties

### basemap

```ts
readonly basemap: BasemapDefinition;
```

The active basemap. A change is applied to the mounted engine with `setBasemap`.

### children

```ts
readonly children?: ReactNode;
```

Overlays and other content that reads the map through `useMap`.

### chrome

```ts
readonly chrome?: (map: ReactNode) => ReactNode;
```

Renders the chrome around the map, inside the map context. It receives
the map region (with its hidden keyboard help) and returns the tree to
render in its place, so controls that call `useMap`, such as the scale
bar and the credits, can sit beside the map rather than inside it:
`chrome={(map) => <MapChrome background={map} ... />}`. Called on every
render; put hooks in the components it returns, not in the function.

### cursor

```ts
readonly cursor?: MapCursor;
```

Defaults to `grab`.

### id

```ts
readonly id?: string;
```

The id of the map region, for example the target of a skip link.

### initialView

```ts
readonly initialView: ViewState;
```

The view the engine mounts with. Later changes are ignored.

### keyHelp

```ts
readonly keyHelp?: readonly MapKeyHelpEntry[];
```

Extra lines for the hidden keyboard instructions, after the map's own,
for the keys a tool adds while it is open. Descriptions are used as
written, so write each as a complete sentence without a trailing full
stop.

### label

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

The name of this map, in the language of the page, for a page with more
than one: "Pine" makes the map region "Map (Pine)", the search "Search
(Pine)", the map tools "Map tools (Pine)", and so on for the map scale,
the measuring and drawing toolbars and the credits, so no two landmarks
on the page share a name. Leave it out for a page with one map, where the
names stay as they are. A sheet's name is its `title`, which the host
writes.

### onBasemapApplied

```ts
readonly onBasemapApplied?: (basemap: BasemapDefinition) => void;
```

Called when a change of `basemap` has loaded on the mounted engine, so
the app can save the choice only once it is known to work.

### onBasemapError

```ts
readonly onBasemapError?: (error: MapEngineError, failed: BasemapDefinition, kept: BasemapDefinition) => void;
```

Called when a change of `basemap` could not load. The map keeps drawing
`kept`, the basemap that last loaded, and this is not an engine error:
`useMap().error` stays null. Passing `kept` back as `basemap` causes no
second swap.

### onBasemapUnavailable

```ts
readonly onBasemapUnavailable?: (basemap: BasemapDefinition) => void;
```

Called when every tile of the basemap being drawn failed to load and none
loaded, once the map settled (its provider is down). The map keeps
working, so the host decides whether to draw another basemap instead.

### onClick

```ts
readonly onClick?: (event: MapClickEvent) => void;
```

A click or tap on the map. Not called for the click that ends a long-press.

### onDropPinKey

```ts
readonly onDropPinKey?: () => void;
```

The P key, which drops a pin at the centre of the map.

### onEngineError

```ts
readonly onEngineError?: (error: MapEngineError, basemap: BasemapDefinition) => void;
```

Called when the engine cannot start or stops working. The
app decides what to show, for example a message when WebGL is missing.

### onEscape

```ts
readonly onEscape?: () => void;
```

The Escape key while the map has focus.

### onIdentifyKey

```ts
readonly onIdentifyKey?: () => void;
```

The I key, which lists the features at the centre of the map.

### onKeyCommand

```ts
readonly onKeyCommand?: (event: KeyboardEvent_2<HTMLElement>) => boolean;
```

Runs before the map's own keys, with each key pressed on the map region.
Return true to say the key was handled: the map then does nothing with it
and its default is prevented. A tool uses this to take keys the map would
otherwise use, such as the arrows that move a selected point.

### onLongPress

```ts
readonly onLongPress?: (event: MapLongPressEvent) => void;
```

A long-press (touch or mouse) or a right-click.

### onPointerMove

```ts
readonly onPointerMove?: (latlng: LatLng | null) => void;
```

The position under a mouse or pen, at most once per frame, or null when
it leaves the map. For the cursor coordinates readout; touch is ignored.
Leaving the map for `MapReadout` reports nothing, so the coordinates stay
put while the readout grows under the pointer: pass `MapReadout` an
`onCursorLeave` that clears the position, or it stays shown after the
pointer leaves the readout.

### onViewChange

```ts
readonly onViewChange?: (view: ViewState) => void;
```

Called when the view stops changing (`moveEnd`), not on every frame.

### testId

```ts
readonly testId?: string;
```

Sets `data-testid` on the map region.

## See also

- [`BasemapDefinition`](https://docs.mapcairn.com/api/core/BasemapDefinition.md)
- [`MapCursor`](https://docs.mapcairn.com/api/map/MapCursor.md)
- [`ViewState`](https://docs.mapcairn.com/api/core/ViewState.md)
- [`MapKeyHelpEntry`](https://docs.mapcairn.com/api/core/MapKeyHelpEntry.md)
- [`MapEngineError`](https://docs.mapcairn.com/api/core/MapEngineError.md)
- [`MapClickEvent`](https://docs.mapcairn.com/api/core/MapClickEvent.md)
- [`MapLongPressEvent`](https://docs.mapcairn.com/api/map/MapLongPressEvent.md)
- [`LatLng`](https://docs.mapcairn.com/api/core/LatLng.md)

Source: [packages/map/src/host/MapView.tsx:39](https://github.com/MapCairn/mapcairn/blob/main/packages/map/src/host/MapView.tsx#L39)
