Skip to main content

DataLayers

What useDataLayers returns: the layers' state and every action on them.

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

Signature​

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

interface DataLayers

Properties​

catalogue​

readonly catalogue: CatalogueView;

What the catalogue is doing besides holding layers: loading, failed, how many definitions it skipped, and how a refresh went.

choices​

readonly choices: readonly SelectedFeature[] | null;

The features a tap or the keyboard found together, when there were several, so one can be chosen. Null when no list is open. The open card offers a way back to it while it is.

consumeFocus​

readonly consumeFocus: () => void;

Marks the latest focus request as acted on.

credits​

readonly credits: readonly LayerAttribution[];

The credits of the layers that are on, for the map credits.

detail​

readonly detail: DetailState | null;

The affected area of the open card's feature, while it loads or is shown, or null.

focusPending​

readonly focusPending: boolean;

True from a request for the card to take focus until DataLayers. The section that shows the card is unmounted whenever the sheet closes, so what has been acted on is kept here: reopening the sheet later must not repeat it.

focusRequest​

readonly focusRequest: number;

Grows each time opening a card asks for it to take focus (a tap on the map).

identifying​

readonly identifying: boolean;

True from the start of DataLayers until it settles or is cancelled. It is the status data for a "looking up" line, which waits a moment before it shows so a quick answer never flickers.

layers​

readonly layers: readonly DataLayerState[];

Every registered layer, in catalogue order. Empty while the catalogue is loading or has failed.

now​

readonly now: () => number;

The clock the hook uses, for relative times in cards and lists.

selected​

readonly selected: SelectedFeature | null;

The feature whose card is open, or null when none is.

turnedOff​

readonly turnedOff: TurnedOff | null;

The batch Undo would turn back on, or null when none is on offer (none yet, used, replaced, expired or every layer of it already on again).

urlValue​

readonly urlValue: LayersUrlState;

The layers part of the permalink: the layers that are on, and the link's layers still waiting for a catalogue that is loading or has failed, so writing the address does not erase them.

Methods​

backToChoices​

backToChoices(options?: {
readonly focus?: boolean;
}): void;

Closes the open card and returns to the list of features found together.

  • options? ({ readonly focus?: boolean; })

cancelIdentify​

cancelIdentify(): boolean;

Cancels the tap in flight, if there is one: its requests are aborted and it opens and says nothing. Returns whether there was one. The host calls it when the person leaves the plain map (another surface opens, taps stop meaning "look here", a long press), and Escape calls it before it closes anything. A layer turned off, whose tiles change, or an unmount cancels what concerns it without a call, and so does opening a card or a list with DataLayers or DataLayers.

choose​

choose(hits: readonly {
readonly layerId: string;
readonly featureId: string;
}[], options?: {
readonly focus?: boolean;
}): void;

Handles several features found at once (a tap or the keyboard route): with one it opens its card, with more it opens the list to choose from, and with none it does nothing. Features no loaded layer has are dropped.

  • hits (readonly { readonly layerId: string; readonly featureId: string; }[])
  • options? ({ readonly focus?: boolean; })

hideDetail​

hideDetail(): void;

Closes the affected area and cancels its request if it is still running.

holdUndo​

holdUndo(by: UndoHolder): void;

Pauses the offer's countdown while by is on its status. The countdown waits until every holder has released.

  • by (UndoHolder)

identifyAt​

identifyAt(target: IdentifyTarget, options?: {
readonly focus?: boolean;
}): Promise<IdentifyResult | null>;

Asks the raster layers that answer a tap what is at a place, and opens what they find: one feature opens its card, several open the list to choose from, and none leaves an open card alone.

It asks each layer that is on, has an identify block, shows imagery and whose bounds hold the place, at most MAX_IDENTIFY_LAYERS in catalogue order. The requests start together, each with IDENTIFY_TIMEOUT_MS to answer. It waits for all of them, changes the state once and says one message: how many were found, which layers did not answer, and how many it asked when the cap held some back. A layer that did not answer leaves what it showed before as it was.

Resolves with how many layers were asked and how many features they found, or with null when this tap was replaced or cancelled before it settled, which opens and says nothing. When no layer can be asked it resolves at once with asked of zero, changes nothing and says nothing, so the caller can fall back to its own message. Starting a tap cancels the one in flight.

  • target (IdentifyTarget)
  • options? ({ readonly focus?: boolean; })

releaseUndo​

releaseUndo(by: UndoHolder): void;

Ends by's hold; once none is left the countdown starts again, in full.

  • by (UndoHolder)

reportTilesRecovered​

reportTilesRecovered(id: string, tiles: string): void;

Records that a tile loaded for the tiles a layer had reported slow or with no tiles, which MapDataLayers calls from the adapter's report. The layer's status goes and the layer says so once, politely. A recovery for any other tiles, or for a layer that is not showing the status, is ignored.

  • id (string)
  • tiles (string)

reportTilesSlow​

reportTilesSlow(id: string, tiles: string): void;

Records that a tile layer has had tiles asked for and none has loaded for a long while, which MapDataLayers calls from the adapter's report. tiles is the template those tiles came from: a report for anything but the layer's current tiles, or for a layer that is off, is ignored, as is one for tiles the layer already reported as slow or unavailable. The layer then says it is still waiting, and announces it once in a message that is kept, because the person turned the layer on and would otherwise see nothing, until its tiles change, it is turned off, or a tile loads later (see DataLayers).

  • id (string)
  • tiles (string)

reportTilesUnavailable​

reportTilesUnavailable(id: string, tiles: string): void;

Records that the map settled with none of a tile layer's tiles loaded, which MapDataLayers calls from the adapter's report. tiles is the template those tiles came from: a report for anything but the layer's current tiles, or for a layer that is off, is ignored. The layer then says so and announces it once, until its tiles change, it is turned off, or a tile loads later (see DataLayers). It replaces the status of a layer reported slow for the same tiles.

  • id (string)
  • tiles (string)

retry​

retry(id: string): void;

Loads a layer again after its load failed. It has no effect on a layer that loaded.

  • id (string)

retryCatalogue​

retryCatalogue(): void;

Asks the catalogue to load again after a failed load or a failed refresh, which the section's Try again does. It does nothing in any other state: only the host refreshes a catalogue that is working.

select​

select(layerId: string, featureId: string | null, options?: {
readonly focus?: boolean;
readonly keepChoices?: boolean;
}): void;

Opens a feature's card, or closes it (and any list) with null. A card opened without keepChoices also closes the list of features found together.

  • layerId (string)
  • featureId (string | null)
  • options? ({ readonly focus?: boolean; readonly keepChoices?: boolean; })

setControl​

setControl(id: string, controlId: string, value: string): void;

Sets one of a layer's controls (a date, a range, a choice) to a value, resolved against the definition. The value is kept while the layer is off.

  • id (string)
  • controlId (string)
  • value (string)

setEnabled​

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

Turns a layer on or off. An unknown id, or a layer already in that state, is ignored. Turning a layer off closes its open card and list of choices.

  • id (string)
  • enabled (boolean)

setSort​

setSort(id: string, sortId: string): void;

Chooses how a layer's list is ordered, by the id of one of the sort options in its definition.

  • id (string)
  • sortId (string)

setView​

setView(area: Bounds, zoom: number): void;

Tells layers what the map shows, once it has settled: the visible box and the normalised zoom. A query layer asks for the features in a window around it. A layer with a zoom window in its definition (a query layer's minzoom, a vector tile layer's minzoom and maxzoom) says which level to zoom to when the zoom is outside it.

  • area (Bounds)
  • zoom (number)

showDetail​

showDetail(layerId: string, featureId: string): void;

Asks the layer's provider for the affected area of a loaded feature, replacing any area already shown or being fetched. An unknown layer or feature is ignored.

  • layerId (string)
  • featureId (string)

turnOff​

turnOff(ids: readonly string[], options?: {
readonly group?: string;
}): void;

Turns several layers off as one change: one state update, so one redraw and one address update, and one announcement ("3 layers turned off. Undo available"). Ids that are not on, or not known, are ignored, and nothing happens when none is on. Each layer's open card, list of choices and affected area close as they do for a single layer. It offers DataLayers for UNDO_TIMEOUT_MS, replacing any earlier offer. group says which group's action asked, so the ui can tell a group's action from the one for every layer; it is not words, and the ui finds the group to show the Undo beside by TurnedOff.

  • ids (readonly string[])
  • options? ({ readonly group?: string; })

undoTurnOff​

undoTurnOff(): void;

Turns back on the layers of the last DataLayers, in one change and one announcement. A layer's control values stay while it is off, so they come back as they are. A layer that is on again, or no longer in the catalogue, is skipped; the rest of what the person changed meanwhile is left as it is. Does nothing when no offer is open.

See also​

Source: packages/map/src/layers/useDataLayers.ts:145