Skip to main content

MapContextValue

What useMap 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​

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

interface MapContextValue

Properties​

adapter​

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​

readonly canZoomIn: boolean;

False once the zoom is at maxZoom.

canZoomOut​

readonly canZoomOut: boolean;

False once the zoom is at minZoom.

error​

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​

readonly focusMap: () => void;

Moves keyboard focus to the map region without scrolling.

hostElement​

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​

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​

readonly loading: boolean;

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

maxZoom​

readonly maxZoom: number;

The highest normalised zoom the active basemap allows.

minZoom​

readonly minZoom: number;

Normalised zoom limits of the active basemap.

onUserZoom​

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​

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​

readonly retry: () => void;

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

tileError​

readonly tileError: boolean;

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

view​

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​

Source: packages/map/src/host/MapContext.ts:12