Skip to main content

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​

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

interface MapAdapterControls

Properties​

basemap​

readonly basemap: BasemapDefinition;

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

host​

readonly host: MapHostElement;

The element the adapter mounts into.

hostSize​

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

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

Methods​

createFailingMount​

createFailingMount?(): MapAdapter;

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

drawnLayers​

drawnLayers(): readonly DrawnLayer[];

Describes the data layers the engine draws, lowest first.

failNextBasemap​

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​

failNextImage?(): void;

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

pointerDown​

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​

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

Makes the engine report the pointer moving to a position.

  • latlng (LatLng)
  • pointer? ("mouse" | "touch")

pointerUp​

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

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

  • latlng (LatLng)
  • pointer? ("mouse" | "touch")

settle​

settle(): Promise<void>;

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

simulateBasemapUnavailable​

simulateBasemapUnavailable(): void;

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

simulateClick​

simulateClick(latlng: LatLng): void;

Makes the engine report a pointer click at a position.

  • latlng (LatLng)

simulateFatalError​

simulateFatalError(): void;

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

simulateFeatureHits​

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​

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​

simulateLoading(loading: boolean): void;

Makes the engine report that loading started or finished.

  • loading (boolean)

simulateTileError​

simulateTileError(): void;

Makes the engine report a failed tile or style request.

simulateTileLayerFailure​

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​

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​

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​

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​

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​

Source: packages/core/src/contracts/mapAdapter.contract.ts:34