Skip to main content

Data layers

Part of Architecture, which is built from ARCHITECTURE.md in the repository, where it is edited.

How data layers are defined, loaded and shown on the map.

A data layer is typed data: a LayerDefinition in packages/web/src/layers/definitions/, one file each, collected with import.meta.glob. Nothing in the code branches on a layer id, a provider or a response shape.

A layer's path from file to map, for a feed layer, with arrows in the order things happen. createServices() passes the catalogue and FetchLayerSource to the ui. A tile or vector layer has no load step: MapDataLayers hands the adapter its source, and the engine requests the tiles.

Diagram of 6 boxes and 5 arrows At start-up holds definitions/*.ts one LayerDefinition each; createStaticLayerCatalogue validates every definition. When a layer is turned on holds useDataLayers in packages/map; LayerSource.load FetchLayerSource in packages/web; MapDataLayers setFeatureLayer and its kin; MapAdapter MapLibre adapter draws it. definitions/*.ts one LayerDefinition each points to createStaticLayerCatalogue validates every definition. createStaticLayerCatalogue validates every definition points to useDataLayers in packages/map. useDataLayers in packages/map points to LayerSource.load FetchLayerSource in packages/web. LayerSource.load FetchLayerSource in packages/web points to MapDataLayers setFeatureLayer and its kin. MapDataLayers setFeatureLayer and its kin points to MapAdapter MapLibre adapter draws it. At start-up When a layer is turned on definitions/*.ts one LayerDefinition each createStaticLayerCatalogue validates every definition useDataLayers in packages/map LayerSource.load FetchLayerSource in packages/web MapDataLayers setFeatureLayer and its kin MapAdapter MapLibre adapter draws it
  • Core (packages/core/src/layers) holds the definition types and a hand-written schema check (validateLayerDefinition; core stays free of schema libraries), URL and card templates ({window}, {time|relative}; a tile URL leaves the engine's {z}, {x}, {y} and {bbox-epsg-3857} alone, while an identify URL fills {x} and {y} itself), host-keyed card, list, feed-shape label and unit templates (LayerTemplate), derived URL variables looked up from control values, filters, a decoder registry with the built-in geojson decoder (fields mapped by dotted path, so USGS and GDACS share it), a formatter registry (relative, number, km, date), style evaluation with a legend derived from the style, palette slot names, and SharedResponseCache, which reuses a response for its max-age (or the definition's cacheSeconds) and shares a request in flight, so layers split from one feed cost one request. It also holds the LayerCatalogue implementations and partitionDefinitions (see "Ports").
  • The LayerSource port loads any feed definition with load({ definition, controls, now, signal }) and an on-request loadDetail, and rejects only with a typed LayerError (network, invalid, empty, aborted). A detail URL comes from the provider's data, so it is requested only when it is https on an origin the definition declares. Its third method, identify({ definition, controls, now, at, signal }), asks what a tile layer's identify block says is at a tap and is required, so a host's own LayerSource must implement it. Nothing found resolves to an empty list, never empty; it rejects with network (which includes any error status, 401 and 403 too until an unauthorised kind exists), invalid (a URL that cannot be built or is not https, which core's identifyRequestUrl checks for every source, or an answer that is not a document the decoder reads) or aborted. The size of an answer belongs to the source: one that reads from a network applies a limit of its own to every answer and refuses a larger one as invalid, so the contract suite requires it. FetchLayerSource reads at most MAX_IDENTIFY_RESPONSE_BYTES (1 MiB) of an identify answer and at most maxResponseBytes of a feed, query or detail answer, checked against Content-Length and again while reading, which stops and cancels the stream at the first chunk over the line. maxResponseBytes is an option of the source (FetchLayerSourceOptions), not of a definition, so it is the same for every layer the source serves: one large layer raises it for all of them. It defaults to DEFAULT_MAX_RESPONSE_BYTES (4 MiB, in FetchLayerSource.ts), a limit the recorded fixtures are far below (they are trimmed samples, so no test ties the limit to a real feed), and a test in layers.test.ts requires it to be at least four times the largest size any detail source's dataCost states. An over-limit answer is not kept in the response cache, and the layer shows the same error state and message as any other invalid answer. The identify path sends the request through the same private fetch-and-parse method as every other request, but never through SharedResponseCache: a tap's URL never repeats, and a kept answer would push feed responses out of the cache, so it ignores Cache-Control and shares no request in flight. FakeLayerSource scripts identify apart from load (setIdentified, failIdentify, holdIdentify(layerId) for one layer, and identifyRequests with the URL a real source would fetch) and applies no size limit to an identify answer. setOversizeAnswer(layerId, kind) makes a layer's feed or detail answer larger than the source's limit, so it refuses it as invalid, and a host can script "features load, detail refused". The LayerSource contract suite covers identify with two layers, CONTRACT_IDENTIFY_LAYER and CONTRACT_OTHER_IDENTIFY_LAYER, and LayerSourceControls has four required members beyond the feed ones: respondToIdentifyWith, failIdentifyWith and holdIdentify for identify, and respondWithOversizeAnswer(kind) for the size limit (the subject makes its source answer a feed or a detail with a body larger than whatever limit it applies, and the suite requires the read to fail as invalid and an answer within the limit to load), so a host that runs the contract against its own source must supply them. useDataLayers.identifyAt calls it (see "Identify at a tap" below); the reference site's layers have no identify block, so nothing asks it there.
  • Map (packages/map/src/layers) has useDataLayers (state, loading, cancellation, announcements, the permalink value), MapDataLayers (draws through the adapter, turns taps into open cards), SelectionMarker, and the generic LayersSection, card and list. "Show on map" in LayersSection fits a polygon or line with fitPadding, clear of the sheet (at its half detent) or the side panel, the search pill and the end stack, and above the map key while it shows: MapChrome publishes how far up from the bottom edge the key reaches (mapKeyClearance in the chrome layout context), and the fit keeps clear of it where that still leaves twice REVEAL_CLEARANCE of map. A point is centred in what the sheet or panel leaves free. The data palette values live in @mapcairn/theme (tokenValues.dataPalette).
    • How useDataLayers loads. Its load effect is four small steps, each a pure function beside the hook. wantedLoads (loadRequests.ts) resolves what each enabled layer asks for, as a request key and, for a query layer, a window. planLoads decides what to cancel, forget and start by comparing those keys with the requests in flight and settled. loadOutcome (loadOutcome.ts) loads one request through the LayerSource and works out what the layer then shows and says, and reportLoad and reportZoomLimits (loadReport.ts) say it, once for a query layer. A render writes no ref: the window a query layer chose is remembered, and the committed state the handlers read is kept, in effects, so a render React throws away (a transition that suspends) leaves nothing behind.
    • Turning layers off at once. useDataLayers.turnOff(ids, { group }) turns several layers off in one state change, so the engine is drawn once and the address changes once, and announces once ("3 layers turned off. Undo available"). It clears each layer's results, selection, choices, tiles known to have failed and affected area exactly as setEnabled(id, false) does (both use withoutTraces), and the load plan cancels the layers' open requests. It records the ids as an undo offer: turnedOff reports how many of them are still off and in the catalogue (null when none is, so the offer never claims more than is true), and undoTurnOff() turns those back on in one change and announces once. A layer keeps its control values while it is off, so Undo needs no snapshot of them. The offer is state, not a ui timer: it lapses after UNDO_TIMEOUT_MS (10 seconds), is replaced by the next batch, and does nothing once gone, so a closed and reopened sheet never shows a stale one. holdUndo(by) and releaseUndo(by) pause the countdown for a holder (pointer or focus), and it restarts in full once neither holds. Other changes the person makes meanwhile do not cancel the offer. There is no batch that turns layers on.
    • A catalogue that loads or changes. useDataLayers keeps the layers a link names (its initial option) as a waiting list, apart from the layers that are on. A catalogue that is ready at mount, as the static one is, resolves the list at once, and an id it does not have is dropped without a word, so the reference site behaves as before. While the catalogue is loading or has failed there are no layers, so the ids wait and urlValue keeps them, with the link's control values as written. useViewPersistence writes whatever urlValue holds on each settled view and each change to it, so the address keeps them. A link carries at most 20 layers (parseUrlHash) and nothing can be turned on while there are no layers, so the waiting ids stay within that; the readable ids past the 20 arrive as LayersUrlState.dropped, which the hook keeps beside the waiting ids (Link.dropped) until the first list. When a list arrives, each waiting id it has is turned on with its control values resolved against the definition, and each it has not (missing, or not offered to this person) is dropped for good: a later refresh that lists it does not turn it on. Only a catalogue that was not ready at mount says so, once. Every state the catalogue publishes is taken in during the render that sees it, and a ready list with a change goes through the pure reconcile (catalogueReconcile.ts), so no render holds a layer without its controls. reconcile counts the waiting ids the list lacks together with Link.dropped as linkMissing, and returns the link emptied, so the count is said once; urlValue is built from the ids and values only, so the count never reaches the address. It also reports the ids the list added and removed, which feed the "Layers updated" message; the skipped count comes from the catalogue's own state. A layer that arrives gets its controls' defaults, a layer whose definition object changed keeps the control values that are still valid and takes the default for the rest, and one whose definition is the same object keeps its values as they are. An enabled layer that is no longer listed is turned off as setEnabled(id, false) turns it off: the load plan aborts its request, and its results, selection, choices and affected area are cleared. It also leaves the address. A layer removed from the list, on or off, leaves any Undo offer as well, so Undo never turns on a layer that was removed and listed again. What a transition says aloud is worked out by the pure catalogueNotice (catalogueNotice.ts), kept in the state and spoken once from an effect, so a render that React repeats says nothing, and each state is said once, when it is entered. A new list is one polite message from announceCatalogueChange (core), in a fixed order: the layers turned off ("Rainfall is no longer available and was turned off." for one layer, "2 layers are no longer available and were turned off." for several), the layers of the link that are not available ("1 layer in the link is not available.", for a catalogue that was awaited), the definitions that could not be shown ("1 layer could not be shown.", said each time the count changes to a number above zero, the first list included), what a refresh added and removed ("Layers updated: 1 added, 1 removed.", with a part that is zero left out, and only for a list that follows one already shown), and "No layers are available." when the first list of an awaited catalogue is empty. Two states are separate messages: "Loading layers", polite, said only while a layer named by the link is waiting, and a failed load ("Layers could not be loaded.") or a failed refresh ("Layers could not be updated. Showing the last list."), assertive. The announcer coalesces messages that arrive within its window (THROTTLE_MS, 600 ms) to the latest of them, except kept ones, which queue behind each other in order, and the same words twice within DEDUPE_MS are said once. Every catalogue message but "Loading layers" is sent with the announcer's keep option, because each is the outcome of a discrete change (a list arriving, a load or refresh failing), so a later message, such as the load result of a link layer, queues behind it and does not replace it (#111, fixed by #144). "Loading layers" is not kept: it is a state, not an outcome, and a later message may replace it.
    • A replaced definition is drawn again. For each map id, MapDataLayers remembers what it last handed to the adapter, which includes the definition object, compared by identity (Drawn in MapDataLayers.tsx). A layer is drawn again through the same adapter method as before (setFeatureLayer or setStyledShapes for a feed, setHeatmapLayer, setVectorLayer with a setHeatmapLayer for each heatmap source layer, or setTileLayer) when its definition is another object, as well as for the changes that already redrew it: a feed's or heatmap's features, the control values of a heatmap or vector layer, and a raster layer's URL or opacity. So a refresh that changes only a style, a heatmap setting, a vector layer's zoom limits, a raster layer's tile size, zoom limit or bounds, or the colour of a shown affected area (its layer's detail block) shows the change. A definition that is deeply equal to the earlier one keeps the earlier object (partitionDefinitions), so a refresh that changes nothing draws nothing, and a change of URL together with the definition draws once. A feed whose definition is replaced is drawn from the features it already has, and they are requested again only when its request URL changes or it is retried (loadRequests.ts), so a host puts a version in the URL when the data changes. The same holds for a change to how features are decoded (the decoder, the field map or the filter, applied in packages/core/src/layers/feed.ts when the response is read), including a style, label or list that now names a field the field map did not read: the features already loaded are not read again, so the change needs a new URL or a retry to take effect. A change to the style, label or list alone, over fields already read, shows at once. A load already in flight when the definition is replaced finishes with the old definition's decoder and is announced under it, because startLoad in useDataLayers.ts captures the definition and the request key does not change. Each draw method replaces what is under its id in one call, and MapDataLayers draws every layer before it removes the ids it no longer draws, so a replaced layer is never removed first and does not flicker; what is left over, such as a heatmap source layer the new definition no longer has, is removed afterwards. The reference site's static catalogue never replaces a definition, so it draws as before.
  • Web registers the definitions and FetchLayerSource in createServices(). A loop test (src/layers/layers.test.ts) checks every definition against the schema, the production CSP (a layer's feed, detail, tile and identify origins in connect-src, and its tile origin in img-src), ATTRIBUTIONS.md and a recorded fixture, and names what is missing.
  • Layer kinds. A definition is one of five kinds, which decide what the ui offers: points, shapes, heatmap, tiles or vector. The guards isFeedLayer, loadsFeatures, isHeatmapLayer, isVectorTileLayer and isShapeStyle tell them apart, and the ui reads those, not a kind name. A feed layer's style is a point style (no kind) or a shapes style for polygons or lines: a colour rule (fixed, category, steps from explicit class breaks, or intervals, equal classes over a numeric field worked out from min, max and the ramp's length), a pattern, dash and width per class, a fill opacity and a label template. Validation requires a second signal beside colour: a different pattern, width or dash in every class, or a label that names the field. A heatmap layer draws a feed or query as density with radius and intensity taken from range controls and an opacity control; its legend names each step of the ramp in words. A vector-tiles layer has a tile URL, a zoom window for the layer and for each source layer, and a style or heatmap per source layer; its colour rules and label read tile properties by name. Features of a vector tile layer stay in the tiles, so it has a key and no cards or list. A tiles layer may add an identify block that names a URL, a tolerance (a whole number of pixels from 1 to 20, default 12), a decoder, an optional records path, fields and a card. The card is nested, not on the layer, so isFeedLayer and loadsFeatures (which test for a top-level card) do not send the layer to load; isIdentifiable, hasCard (a feed layer or an identifiable one) and cardOf (a feed's card, or identify.card) are how code asks. Core builds the request (identifyUrl: a square of 2 * tolerance + 1 pixels centred on the tap, {bbox} in EPSG:3857 metres and not clamped at the edges of the world, {width}, {height}, {x}, {y}, {lng}, {lat} and {zoom}) and decodes the answer (decodeIdentify: GeoJSON, or a JSON list at records; a feature with no geometry is placed at the tap, nothing found is an empty list, and at most 20 features are kept). Validation (validateIdentify.ts) reports problems as identify.url, identify.fields.id and so on, requires an https URL whose scheme, host and port hold no placeholder, and refuses a control or derived variable named like one of those variables. LayerSource.identify asks it (see "The LayerSource port" above) and useDataLayers.identifyAt calls it for a tap. LayerItem says "Tap the map to see details for this layer." after the legend of an identifiable layer that is on, and LayersSection says "Only the first 4 layers are asked on one tap." once when more than MAX_IDENTIFY_LAYERS identifiable layers are on. The waiting line is described under "Identify at a tap". The guide is in sites/docs/docs/guides/extending.md.
  • Shape template types. ShapeStyle keeps its previous string-only label type by default, preserving vector-layer label assignment. Feed shapes that use host-keyed labels use FeedShapeStyle; vector-tile layers use the default ShapeStyle, and validation keeps their labels to one raw property template.
  • Query layers. A query source asks only for the features in view. The URL uses {west}, {south}, {east} and {north} (and {limit}, one above the cap, so a response shows that more exist). MapDataLayers reports the view (useDataLayers.setView) when a query layer, or any layer whose definition has a zoom window (hasZoomWindow), is turned on and again after the map has been still for 400 ms. nextQueryWindow keeps the last window while the view stays inside it and is not much smaller, and otherwise takes a new one snapped to a grid, so small pans send nothing and nearby views share a request. A provider takes a box inside -180 to 180, so the window is clamped there, except for a view across the antimeridian: its window is the short box (west inside -180 to 180, east past 180, as boundsOfPoints returns) and queryBoxes splits it into the part from west to 180 and the part from -180 to the rest. feedUrl throws for a window across the line (it used to clamp it, which asked for the wrong area), and feedUrls gives one URL for each box and decodeFeeds joins the answers, keeping a feature both hold once (the same id and the same geometry), giving a different feature that shares an id a new one (a decoder's position for a feature with no id starts again in each response), and applying maxFeatures to the whole; FetchLayerSource and the fake both go through them, and if either request fails the other is stopped and the layer shows its error with no partial result, by design. Each half is capped at maxFeatures plus one by the provider, so a view across the line can fetch up to twice the data of one that does not. A view across the line therefore sends two requests instead of one, to the same provider and with the same values otherwise; every other view sends one as before. A window's request key is the URLs of its boxes, so it is one load. One load is in flight per layer: a new window cancels the old one. The layer keeps what it draws while the next window loads, draws at most maxFeatures and says "Showing the first N. Zoom in to see more.", and below its own minzoom asks for nothing and says "Zoom in to level 9 or closer to load this layer." (the level is the definition's minzoom, a normalised zoom, so it needs no conversion). A vector tile layer outside its own minzoom and maxzoom says the same, or "Zoom out below level 12 to see this layer.": layerZoomLimit in core reads the window from the definition, and the status is { kind: "zoom-in" | "zoom-out", level }. A layer without a window says nothing about zoom. A query layer announces each state once, so a pan to another window is silent; a layer outside its window says so once, and again after it has been back inside.
  • The key. legendFor (core) derives a layer's key from its definition. LayerKey (packages/map/src/layers) draws it, and both the Layers section and MapKey use it, so the two cannot drift. mapKeyBlocks turns the layers' state into the blocks of the map key (the layers that are on and have a key, in catalogue order, each with the day or time its controls say, from describeChosenTime), as plain data for any drawing. MapKey renders them in MapChrome's mapKey slot and holds only whether it is minimised, in memory; it requests and stores nothing.
  • Open card. The feature whose card is open is useDataLayers's selected, set by select. A tap that finds several features calls useDataLayers.choose(hits): one opens its card, several open FeatureChoices, a list of rows that each open a card, and the card offers "Back to list". The I key runs the same route from the centre of the map (featuresAt), and says when nothing is there. The open card keeps a snapshot of its feature, so a query layer's card survives a refresh for another part of the map. It is not the selected set below. FeatureCard and FeatureChoices read the card template through hasCard and cardOf, so a feature found by a tap on a tile layer opens the same card and row: with no style it has no glyph and no class line, and no "Show affected area". LayersSection and featureTitle do the same. Identified features are not selectable, because their ids are not stable from one tap to the next, and selectableRefs only admits a feed layer's.
  • Identify at a tap. useDataLayers.identifyAt(target, { focus }) (packages/map/src/layers/useDataLayers.ts, with identifyRun.ts beside it) asks every tile layer that is on, has an identify block (isIdentifiable), that the map has not reported tiles-unavailable (a layer reported slow is still asked, because it may be showing part of its imagery) and whose bounds hold the tapped place, at most MAX_IDENTIFY_LAYERS (4) in catalogue order. The requests start together, and each has IDENTIFY_TIMEOUT_MS (8 seconds), counted by the hook (IdentifyRun.ask), which records a timeout itself because a source only sees that its request was aborted. A request ends with the source's answer or with the abort, whichever comes first, so a source that is slow to notice an abort does not hold the tap up. The hook waits for all of them, changes its state once and says one message, then resolves with { asked, found }, or with null when the tap was cancelled or replaced meanwhile, which opens and says nothing. When no layer can be asked it resolves at once with asked of 0 and changes nothing, so the host can fall back to its own message ("No features at the centre of the map."). What a layer found sits in its own state slot, identified (by layer id, with the tile URL it was asked about), apart from results, which feeds the list and the drawing; featuresFor reads one or the other for select and the selected and choices memos, and the layer's own features stay empty. An entry is replaced at settlement, not at the start, for each layer that answered, so a tap on empty ground leaves an open card alone, except a card that points into an entry that was replaced, which closes. A layer that failed keeps what it had. One feature opens its card, several open FeatureChoices through withOpened, the step choose uses for several features, and the caller then opens the sheet (useMapApp.openFeature). An entry is cleared by withoutTraces (turning the layer off, turnOff, a layer leaving the catalogue) and when the layer's tile URL changes, as tilesUnavailable is. A layer that answered before it was turned off, or before its tile URL changed, while another layer was still held, has its answer dropped at settlement (stillCurrent, which reads the committed state), so it neither opens nor is counted.
    • One message. Core's announceIdentified (announce.ts) takes { found, asked, available, failed } and returns the message and priority, or null. Several found: "3 features here. Choose one from the list." One found: nothing, because the card takes focus. None found: "Nothing found here." (not said when every layer failed). Layers that failed or timed out are named after it: "Rainfall did not answer.", "Rainfall and Wind did not answer." or "Rain, Flood and Wind did not answer.". When the cap held layers back it adds "Asked 4 of 6 layers.". asked counts the layers that answered or failed, and a layer cancelled meanwhile (turned off, say) is in neither asked nor available. The message is assertive only when every layer asked failed, and polite otherwise. The hook sends it once, at settlement, with the announcer's keep option, because it reports the outcome of the person's tap and a later message must not replace it; choose also sends its "N features here" message with keep, and the host's "No features at the centre of the map." does too. choose is not used on this route, so it does not announce a second time. identifying is true from the start of a tap until it settles or is cancelled; it is the status data for the "Looking up what is here" line. useIdentifyFeedback(identifying) (identifyFeedback.ts) turns it into a flag that is true only after IDENTIFY_FEEDBACK_MS (400 ms), so an answer that comes sooner shows nothing, and false again as soon as the lookup ends, whether by its answer, a new tap on a drawn feature, a surface change or Escape. IdentifyStatus draws the line, and the host puts it in the bottom-centre slot (AppChrome, above the banners). It is a StatusMessage (variant info), so the wait is said once, politely, by the line's own status region when the line appears at 400 ms, and the visible words and what a screen reader hears are the same, which keeps a person who presses I from pressing it again and restarting the lookup. That is a different live region from the announcer's, so the result, which useDataLayers says through the announcer with keep when it arrives, never replaces the wait or is coalesced with it, whether the answer comes just after the line or much later, or the layers fail. A lookup that answers before 400 ms shows and says no wait, only its result. Escape and the line's dismiss button (onCancel, which hosts pass layers.cancelIdentify) end the lookup and say nothing more. The line's own countdown is longer than IDENTIFY_TIMEOUT_MS, so only the lookup's timeout ends a lookup by itself. A second tap while a lookup waits keeps the line, as the lookup is still waiting, and does not restart its delay.
    • Cancelling. A new identifyAt cancels the one in flight. cancelIdentify() aborts the requests and returns whether there was one in flight. select (when it opens a card) and choose (when it opens one or a list) cancel it too, so a card opened by a tap on a drawn feature, the I key or a list row is never replaced, nor has its focus taken, by a late answer. MapDataLayers calls it when ignoreTaps turns true, and useMapApp calls it when the open surface changes, from onLongPress, and first from onEscape, which closes a surface only when nothing was in flight. onEscape serves both Escape routes: the map region's (MapView's onEscape) and the document-level listener in AppChrome, so one press ends a lookup wherever focus is. A layer that is turned off, leaves the catalogue or changes its tiles has its request aborted when the change commits (IdentifyRun.abortStale), and the other layers' answers still settle. Unmounting aborts every request.
    • The tap route. featureTap fires only for drawn features, so the host's onClick is the route: useMapApp.onMapClick, on the plain map (not Measure, Directions or Draw), calls identifyAt when adapter.featuresAt(event.point) is empty, and identifyAtCentre does the same from the centre of the map, with its longitude wrapped to -180 up to 180 as a click's is, and says nothing until the layers answer. While Measure, Directions or Draw is open the key asks no raster layer, and says "No features at the centre of the map." when no drawn feature is there, as before. The reference site's layers have no identify block, so none of this asks anything there. No host has select mode yet, so nothing stops a raster request while one is on: that gate belongs to plan 0007's select mode when it lands.
  • The selected set. useFeatureSelection(layers, { formatters }) (packages/map/src/layers/useFeatureSelection.ts) holds the host's FeatureSelection store as the ui shows it. The host calls it once, beside useDataLayers, because its state outlives the sheet's sections, which unmount. It reads the store with useSyncExternalStore and returns null when Services.selection is absent. SelectionProvider hands the result down, and useSelection() returns it, or undefined outside a provider or when the host has no store, so a component that selects or lists features renders nothing then and takes no prop for it. The reference host calls it in useMapApp (packages/web/src/app/useMapApp.ts, which returns the result as app.selection) and App.tsx mounts SelectionProvider around MapView, and the example app does the same in ExampleMap (examples/embed/src/ExampleApp.tsx). Each mounts the provider whether or not there is a store, because a provider given null provides nothing and a conditional wrapper would change the tree around the map. createServices() builds no store, so on the reference site the hook returns null, nothing reads the set and the site is unchanged; the example runs on the MemoryFeatureSelection that createFakeServices builds (examples/embed/src/exampleServices.ts). No component reads useSelection() yet.
    • Resolving. resolveSelection (selectionResolve.ts) turns each reference into the feature its layer has loaded, else the snapshot reconcileSnapshots kept while it was loaded, but only while its layer is on and isFeedLayer. Otherwise it is "not shown": it stays in the store and counts. Turning a layer off drops nothing and announces nothing from the selection: useDataLayers says the layers were turned off, and a selection change that follows within the announcer's window is a separate message, sent when the window ends (the turning-off message is kept, so a later selection message that is not kept queues behind it and is spoken when the window ends). Undo brings the references back. An entry holds the layer's definition, not its state, and resolveSelection takes the previous result and returns the same entries, and the same array, when nothing they show changed, so a map move, which makes new layer states with the same features, does not re-render what reads the selection. add ignores a reference whose layer is not a feed layer in the list (selectableRefs).
    • A layer removed from the catalogue. Undo cannot bring such a layer back, so the hook drops its references. It keeps the ids of the last list the catalogue held while it was ready (layers.catalogue.status, so a loading or failed state leaves them as they were). When a ready list lacks an id the last one had, it removes the references to that id with one remove call (refsOfRemovedLayers in selectionResolve.ts), which is one store change and one message with the new total, such as "2 features removed. 1 selected.". A layer that was off when it left is dropped the same way. Nothing is dropped at mount, while the catalogue is loading or has failed, when its first ready list arrives, for a layer no ready list ever held, or for a reference the store hydrates later, because none of these is a removal. A changed definition with the same id is not one either.
    • Messages. toggle, add, remove and clear each announce once through LiveRegion, with the words in core's announce.ts and the choice in selectionMessages.ts. The message is worked out from the set before and after the call, because the store returns nothing: a batch the store refused for its limit is told from a batch of duplicates by changing nothing while a reference was new. Each message carries the new total, because the announcer replaces a waiting message that is not kept with a later one when both arrive within THROTTLE_MS of the last one sent, so the one that is read is still true. The announcer's keep option, used for the outcome of a person's own action such as turning layers off or back on, exempts a message from that replacement; the selection's messages do not use it. A refusal past the limit is assertive, as a refused import is, so a later polite message cannot replace it; the others are polite. A change made outside the hook, such as hydration, updates the entries and is not announced. The select-mode flag is held in the hook and nothing reads it yet. featureTitle (featureTitle.ts) fills the card title template for FeatureChoices and for the messages.
  • Controls. A definition's controls are segmented, switch, date (a UTC day, bounded by fixed days or { daysAgo }), datetime, opacity and range. A range unit uses LayerTemplate and includes its own spacing. A datetime control is a UTC day and a time on a fixed step (stepMinutes, which divides a day), for a product the provider names by timestamp, such as the half-hourly rainfall. Its bounds are fixed slots or { minutesAgo }, counted back from now and rounded down to the step, so a max set to the provider's latency keeps times that are not out yet off the list. Validation refuses a backwards range (fixed or relative), a relative min with a fixed max (it would pass it as time goes on) and a relative bound over about a hundred years (MAX_MINUTES_AGO), and a relative default is clamped to the bounds when it is worked out. Its value is the slot's start written YYYY-MM-DDtHHMM (link-safe), and templateValues hands a URL template the ISO instant instead (2026-11-11T14:30:00Z). Core gets now from the ui's clock (useDataLayers.now): a layer's default slot is fixed when the layer first arrives (at mount for a static catalogue) and resolved again when a refresh replaces its definition, and the offered range and the newest slot shown are worked out again on each render, with no timer and no request of their own. The helpers are in layers/dateTime.ts.
  • Permalink. UrlStateValue.layers is written as #layers=earthquakes,imagery&earthquakes.window=day, together with the view, so neither drops the other. Both serialiseUrlHash and parseUrlHash keep at most 20 layers (MAX_LAYERS), the first 20 in order, so an address the app writes is read back whole; a hand-edited link with more keeps its first 20 distinct readable ids and parseUrlHash counts the rest in LayersUrlState.dropped (left out when zero, never written, and not counted for a repeated, unreadable or empty id, which is skipped as before). That count joins the layers of the link that are not available in the one note a catalogue that was not ready at mount says (see "A catalogue that loads or changes"). Values are resolved against the definition when read, so a hand-edited link cannot reach an unknown control or value: a date or a date and time outside its bounds moves to the nearest bound, and a date and time between steps is rounded down to its slot. Layers the link names that a catalogue still loading has not listed stay in the address until its list arrives (see "A catalogue that loads or changes").