# MapAdapterControls

What the map contract needs besides the adapter itself. A real adapter
supplies its own: a host in jsdom or a browser, and ways to make its engine
report clicks, loading, tile errors, zoom gestures and a failure after load.

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

## Signature

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

## Properties

### basemap

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

A basemap the adapter can mount. Its zoom limits must span at least four
zoom levels.

### host

```ts
readonly host: MapHostElement;
```

The element the adapter mounts into.

### hostSize

```ts
readonly hostSize: {
        readonly width: number;
        readonly height: number;
    };
```

The size of `host` in pixels, as `getBoundingClientRect` reports it.

## Methods

### createFailingMount

```ts
createFailingMount?(): MapAdapter;
```

Builds an adapter whose `mount` rejects with a `MapEngineError`, for
example by hiding WebGL. Optional because some engines cannot fail.

### drawnLayers

```ts
drawnLayers(): readonly DrawnLayer[];
```

Describes the data layers the engine draws, lowest first.

### failNextBasemap

```ts
failNextBasemap?(): void;
```

Makes the next `setBasemap` fail to load its style, for example by
failing the style request. Optional because some engines cannot fail.

### failNextImage

```ts
failNextImage?(): void;
```

Makes the next `toImage` fail, such as a canvas the browser will not
read. Optional because some engines cannot fail.

### pointerDown

```ts
pointerDown(latlng: LatLng, pointer?: "mouse" | "touch"): void;
```

Makes the engine report a pointer going down at a position, as a mouse
or pen (`mouse`, the default) or as a finger (`touch`).

- `latlng` (`LatLng`)
- `pointer?` (`"mouse" | "touch"`)

### pointerMove

```ts
pointerMove(latlng: LatLng, pointer?: "mouse" | "touch"): void;
```

Makes the engine report the pointer moving to a position.

- `latlng` (`LatLng`)
- `pointer?` (`"mouse" | "touch"`)

### pointerUp

```ts
pointerUp(latlng: LatLng, pointer?: "mouse" | "touch"): void;
```

Makes the engine report the pointer going up at a position.

- `latlng` (`LatLng`)
- `pointer?` (`"mouse" | "touch"`)

### settle

```ts
settle(): Promise<void>;
```

Waits until the engine has applied every change so far. A no-op for fakes.

### simulateBasemapUnavailable

```ts
simulateBasemapUnavailable(): void;
```

Makes the engine settle with every tile of the basemap failed and none
loaded, as when the provider is down.

### simulateClick

```ts
simulateClick(latlng: LatLng): void;
```

Makes the engine report a pointer click at a position.

- `latlng` (`LatLng`)

### simulateFatalError

```ts
simulateFatalError(): void;
```

Makes the engine fail after it has loaded, the way a crashed worker does.

### simulateFeatureHits

```ts
simulateFeatureHits(hits: readonly {
        readonly layerId: string;
        readonly featureId: string;
    }[]): void;
```

Makes the engine report one tap that lands on several drawn features,
topmost first (a point, polygon or line each). The same features are what
`featuresAt` finds under the pointer afterwards. A feature that is not
drawn is not under the tap.

- `hits` (`readonly {
        readonly layerId: string;
        readonly featureId: string;
    }[]`)

### simulateFeatureTap

```ts
simulateFeatureTap(layerId: string, featureId: string): void;
```

Makes the engine report a tap on the drawn point `featureId` of the
feed layer `layerId`. If no such point is drawn, the tap lands on
nothing.

- `layerId` (`string`)
- `featureId` (`string`)

### simulateLoading

```ts
simulateLoading(loading: boolean): void;
```

Makes the engine report that loading started or finished.

- `loading` (`boolean`)

### simulateTileError

```ts
simulateTileError(): void;
```

Makes the engine report a failed tile or style request.

### simulateTileLayerFailure

```ts
simulateTileLayerFailure(layerId: string): void;
```

Makes the engine settle with every tile of the tile layer `layerId`
requested and none loaded, as when its provider has no imagery for what
was asked. A layer that was never set has no tiles, so nothing happens.

- `layerId` (`string`)

### simulateTileLayerRecovery

```ts
simulateTileLayerRecovery(layerId: string): void;
```

Makes the engine load a tile of the tile layer `layerId`, as after a
transient failure has passed. A layer that was never set has no tiles, so
nothing happens.

- `layerId` (`string`)

### simulateTileLayerSlow

```ts
simulateTileLayerSlow(layerId: string): Promise<void>;
```

Makes the engine wait, with a tile of the tile layer `layerId` requested
and none loaded, for longer than it waits before calling a layer slow, as
when its provider is not answering. Resolves once that wait has passed. A
layer that was never set has no tiles, so nothing happens.

- `layerId` (`string`)

### simulateUserZoom

```ts
simulateUserZoom(zoom: number): void;
```

Makes the engine report a zoom gesture it handles itself (a wheel, a
pinch or a double-click) that leaves the view at the normalised `zoom`.

- `zoom` (`number`)

### stallNextImageTiles

```ts
stallNextImageTiles?(): void;
```

Makes the tiles of the next requested image (one with a size, a pixel
ratio or a view) never finish loading, and the adapter give up on them
soon. Optional because some engines cannot stall.

## See also

- [`BasemapDefinition`](https://docs.mapcairn.com/api/core/BasemapDefinition.md)
- [`MapAdapter`](https://docs.mapcairn.com/api/core/MapAdapter.md)
- [`DrawnLayer`](https://docs.mapcairn.com/api/core/DrawnLayer.md)
- [`MapHostElement`](https://docs.mapcairn.com/api/core/MapHostElement.md)
- [`LatLng`](https://docs.mapcairn.com/api/core/LatLng.md)

Source: [packages/core/src/contracts/mapAdapter.contract.ts:34](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/contracts/mapAdapter.contract.ts#L34)
