Skip to main content

MapHandle

A map that was drawn in an element.

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

Signature​

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

interface MapHandle

Properties​

layersState​

readonly layersState: MapStore<MapLayersState>;

The layers the map offers and whether each is on, as a store: read it with getState() and listen with subscribe(listener). It is loading, with no layers, until the map has drawn its interface and after destroy(). In releases after 0.2.0, not in 0.2.0 or any earlier release.

ready​

readonly ready: Promise<void>;

Resolves when the engine is drawing. Rejects with a MapEngineError when it cannot start, or a MountMapError of kind destroyed.

Methods​

chooseBasemap​

chooseBasemap(id: string): void;

Picks a basemap as the person does in Map options: the choice is saved, and written to the shared link, once the map has loaded it, and a basemap whose provider proves to be down is undone. update({ basemap }) is the page's own choice and saves nothing. Does nothing after destroy(). In releases after 0.2.0, not in 0.2.0 or any earlier release.

  • id (string)

destroy​

destroy(): void;

Removes the map and everything it added to the page. Safe to call again.

getView​

getView(): ViewState;

The view the map shows, or last showed after destroy().

on​

on<K extends keyof MapHandleEvents>(type: K, listener: (event: MapHandleEvents[K]) => void): () => void;

Listens for an event and returns the function that stops listening.

  • type (K)
  • listener ((event: MapHandleEvents[K]) => void)

setLayerEnabled​

setLayerEnabled(id: string, enabled: boolean): void;

Turns a layer on or off, as its switch does. An id the map does not offer is ignored, and so is a call before the interface has drawn and after destroy(). In releases after 0.2.0, not in 0.2.0 or any earlier release.

  • id (string)
  • enabled (boolean)

setView​

setView(view: Partial<ViewState>, options?: SetViewOptions): void;

Moves the map. Does nothing after destroy().

  • view (Partial<ViewState>)
  • options? (SetViewOptions)

showMeasurement​

showMeasurement(mode: MeasureMode, points: readonly LatLng[]): void;

Opens the measure tool showing these points in this mode, replacing the mode and points of a measurement that is open. No points shows an empty measurement. The input is checked first, so a bad mode or point is an error even when the page did not name the measure tool. Then it does nothing when the page did not name that tool, before the interface has drawn, and after destroy(). The points are copied. In releases after 0.2.0, not in 0.2.0 or any earlier release.

  • mode (MeasureMode)
  • points (readonly LatLng[])

showResult​

showResult(result: Pick<SearchResult, "centre" | "bounds">): void;

Shows a search result as the search box does: the map fits the result's bounds to at most zoom 16, or, for a result with no bounds, moves to its centre at zoom 14. Only centre and bounds are read. It waits for the map to draw, and does nothing after destroy(). In releases after 0.2.0, not in 0.2.0 or any earlier release.

  • result (Pick<SearchResult, "centre" | "bounds">)

update​

update(update: MapUpdate): void;

Changes the basemap or the theme. Does nothing after destroy().

  • update (MapUpdate)

See also​

Source: packages/map/src/element/types.ts:318