Skip to content

LayerManager

Defined in: packages/core/src/renderer/layer-manager.ts:316

Manages map layers and their data sources

new LayerManager(map, callbacks?, data?): LayerManager

Defined in: packages/core/src/renderer/layer-manager.ts:430

ParameterType
mapmaplibregl.Map
callbacks?LayerManagerCallbacks
data?LayerManagerDataOptions

LayerManager

readonly tileJsonFailed: Set<string>

Defined in: packages/core/src/renderer/layer-manager.ts:422

Tile and image sources (url:, pmtiles://, cog://) whose TileJSON or image request failed — a reader chunk that didn’t download, a wrong path — as the renderer saw on the map’s error event; it clears one when its metadata loads. Among failedSources, and setSourceUrl sets an unchanged url again for them, so reload() asks anew.

addLayer(layer, beforeId?, options?): Promise<void>

Defined in: packages/core/src/renderer/layer-manager.ts:1088

Add a document layer. beforeId (live documents, U2) is where an update puts it — the next document layer — and wins over the layer’s own before: while the map has it; otherwise before: is honoured as on first render. awaitData (default on, first render’s load contract: every layer added and its data in) resolves once the layer’s inline url: has been read; off — a live update, which completes when its operations are applied — the layer is placed with its source and the read goes on as a generation-guarded task, as a named source’s does.

ParameterType
layerobjectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<{ id: ZodString; layout: ZodOptional<ZodObject<{ }, "passthrough", ZodTypeAny, objectOutputType<{ }, ZodTypeAny, "passthrough">, objectInputType<{ }, ZodTypeAny, "passthrough">>>; metadata: ZodOptional<ZodRecord<ZodString, ZodAny>>; paint: ZodOptional<ZodObject<{ background-color: ZodOptional<ZodUnion<[ZodEffects<ZodString, string, string>, ZodType<…[], ZodTypeDef, …[]>]>>; background-opacity: ZodOptional<ZodUnion<[ZodNumber, ZodType<…[], ZodTypeDef, …[]>]>>; background-pattern: ZodOptional<ZodUnion<[ZodString, ZodType<…[], ZodTypeDef, …[]>]>>; }, "passthrough", ZodTypeAny, objectOutputType<{ background-color: ZodOptional<ZodUnion<[ZodEffects<…, …, …>, ZodType<…, …, …>]>>; background-opacity: ZodOptional<ZodUnion<[ZodNumber, ZodType<…, …, …>]>>; background-pattern: ZodOptional<ZodUnion<[ZodString, ZodType<…, …, …>]>>; }, ZodTypeAny, "passthrough">, objectInputType<{ background-color: ZodOptional<ZodUnion<[ZodEffects<…, …, …>, ZodType<…, …, …>]>>; background-opacity: ZodOptional<ZodUnion<[ZodNumber, ZodType<…, …, …>]>>; background-pattern: ZodOptional<ZodUnion<[ZodString, ZodType<…, …, …>]>>; }, ZodTypeAny, "passthrough">>>; type: ZodLiteral<"background">; }, ZodTypeAny, "passthrough">
beforeId?string
options?LayerAddOptions

Promise<void>


beginSourceSettlement(): void

Defined in: packages/core/src/renderer/layer-manager.ts:644

Hold named-source releases until settleSources (live documents, KTD4). Claims still count immediately, so during the window a source’s count is never below its true value and nothing is torn down early.

void


destroy(): void

Defined in: packages/core/src/renderer/layer-manager.ts:2207

void


disconnectStream(layerId): void

Defined in: packages/core/src/renderer/layer-manager.ts:2153

Disconnect streaming connection for a layer

ParameterType
layerIdstring

void


failedSources(): ReadonlySet<string>

Defined in: packages/core/src/renderer/layer-manager.ts:737

The sources whose last load failed (see the field), and those whose live updates couldn’t start for want of the live chunk. A copy: safe to hold across an update.

ReadonlySet<string>


getGrid(sourceId): GridField | undefined

Defined in: packages/core/src/renderer/layer-manager.ts:758

A grid source’s field once decoded (grid source, R14); undefined before, or for any other id.

ParameterType
sourceIdstring

GridField | undefined


getSourceData(sourceId): FeatureCollection<Geometry, GeoJsonProperties> | undefined

Defined in: packages/core/src/renderer/layer-manager.ts:572

The GeoJSON this manager last delivered to a fetched/refreshed source, by source id — what fitTo (U14) frames once a url: source’s first fetch lands. Undefined for sources whose data never passed through here.

ParameterType
sourceIdstring

FeatureCollection<Geometry, GeoJsonProperties> | undefined


getSourceExtent(sourceId): [[number, number], [number, number]] | undefined

Defined in: packages/core/src/renderer/layer-manager.ts:1759

The full extent of a source read by view (load: viewport), from the file’s header or metadata — what fitTo frames, since the source’s data is only the part in view. Undefined for every other source.

ParameterType
sourceIdstring

[[number, number], [number, number]] | undefined


getSourceIdForLayer(layerId): string | undefined

Defined in: packages/core/src/renderer/layer-manager.ts:577

The MapLibre source a layer draws from.

ParameterType
layerIdstring

string | undefined


getViewMinzoom(sourceId): number | undefined

Defined in: packages/core/src/renderer/layer-manager.ts:1769

The zoom below which a source read by view reads nothing (its load: { minzoom }), so fitTo doesn’t frame it where nothing draws. Undefined for every other source.

ParameterType
sourceIdstring

number | undefined


getViewZoomThatFits(sourceId, center, from, width, height): number | undefined

Defined in: packages/core/src/renderer/layer-manager.ts:1779

The outermost zoom, from from in, at which a source read by view reads a width × height px view around center (see FormatLoader.zoomThatFits); undefined for any other source, or none.

ParameterType
sourceIdstring
center[number, number]
fromnumber
widthnumber
heightnumber

number | undefined


gridReady(sourceId): Promise<GridField>

Defined in: packages/core/src/renderer/layer-manager.ts:763

A grid source’s field once it is in (R14); see GridSourceManager.ready for what rejects.

ParameterType
sourceIdstring

Promise<GridField>


hasGrid(sourceId): boolean

Defined in: packages/core/src/renderer/layer-manager.ts:753

Whether sourceId is a grid source this manager holds (decoded or not).

ParameterType
sourceIdstring

boolean


hintOnce(layerId, anchor, message): void

Defined in: packages/core/src/renderer/layer-manager.ts:1225

An author hint about a layer’s before: anchor, once per layer and anchor for the life of this manager: a live update re-adds and re-places layers, and the same hint on every update is noise (KTD3).

ParameterType
layerIdstring
anchorstring
messagestring

void


isRefreshing(sourceId): boolean

Defined in: packages/core/src/renderer/layer-manager.ts:1074

Whether a refresh/stream pipeline is running for a named source.

ParameterType
sourceIdstring

boolean


moveLayer(layerId, beforeId?): void

Defined in: packages/core/src/renderer/layer-manager.ts:1133

Move a document layer before beforeId, or to the top (live documents, KTD3). Host layers — anything this manager did not add — are never moved; an anchor the map lacks means the top.

ParameterType
layerIdstring
beforeId?string

void


ownsLayer(layerId): boolean

Defined in: packages/core/src/renderer/layer-manager.ts:679

Whether this manager added layerId — a document layer, as opposed to a host’s.

ParameterType
layerIdstring

boolean


pause(): void

Defined in: packages/core/src/renderer/layer-manager.ts:2090

Stop every pipeline — polling and the by-view loaders — because the map is being replaced by a fallback rebuild (KTD8): no second set of fetches while the next map loads its own. Not resumed; the map is torn down.

void


pauseRefresh(layerId): void

Defined in: packages/core/src/renderer/layer-manager.ts:2113

Pause data refresh for a layer (polling)

ParameterType
layerIdstring

void


readerToken(sourceId): object | undefined

Defined in: packages/core/src/renderer/layer-manager.ts:1823

The identity of a source’s current reader: a new one each time a live update (a changed url:, a reload) recreates it, so classify knows a whole-column scan of the old reader’s file no longer stands.

ParameterType
sourceIdstring

object | undefined


readsByView(sourceId): boolean

Defined in: packages/core/src/renderer/layer-manager.ts:1795

Whether a source holds only the features in view: a FlatGeobuf or GeoParquet source read by view — load: viewport, or a file too large to read whole that switched itself to it. Its data is never the whole dataset.

ParameterType
sourceIdstring

boolean


recreateLoader(sourceId, next): Promise<void>

Defined in: packages/core/src/renderer/layer-manager.ts:980

Destroy a FlatGeobuf or GeoParquet source’s reader and start one from the next document’s source (live documents, U3). A reader suspended because nothing draws the source stays suspended; a read the old reader still had in flight never lands (its generation is over).

ParameterType
sourceIdstring
nextRecord<string, unknown>

Promise<void>


refreshNow(layerId): Promise<void>

Defined in: packages/core/src/renderer/layer-manager.ts:2129

Force immediate refresh for a layer (polling)

ParameterType
layerIdstring

Promise<void>

when the layer has no poll running (as PollingManager.triggerNow does).


registerSources(sources): void

Defined in: packages/core/src/renderer/layer-manager.ts:470

Register the block’s named sources: with MapLibre.

ParameterType
sourcesRecord<string, unknown>

void

Owned here rather than in MapRenderer, which used to call map.addSource directly. That bypassed every piece of refresh machinery, so a named source could declare refresh: and never poll, and it leaked YAML-only keys straight into MapLibre. Registration is idempotent so a re-render does not duplicate sources.


removeLayer(layerId): void

Defined in: packages/core/src/renderer/layer-manager.ts:2157

ParameterType
layerIdstring

void


removeSource(sourceId): void

Defined in: packages/core/src/renderer/layer-manager.ts:689

Remove a named source the document no longer declares (live documents, U2). Refused — the source is left in place — while a document layer still draws it, or while any layer on the map the document did not declare does (KTD4: a host’s layer over a document source).

ParameterType
sourceIdstring

void


replaceLayer(layer, beforeId?, options?): Promise<void>

Defined in: packages/core/src/renderer/layer-manager.ts:1122

Replace a document layer in place (live documents, U2): removed and added again through the same claim path as a fresh add, so the hover.highlight paint wrapping and the generateId rule (ml-aot.142) apply to the replacement. Tolerates a layer the host already removed from the map. With no beforeId the layer keeps its slot on the map (its current successor, host layers included).

ParameterType
layerobjectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<object & object, ZodTypeAny, "passthrough"> | objectOutputType<{ id: ZodString; layout: ZodOptional<ZodObject<{ }, "passthrough", ZodTypeAny, objectOutputType<{ }, ZodTypeAny, "passthrough">, objectInputType<{ }, ZodTypeAny, "passthrough">>>; metadata: ZodOptional<ZodRecord<ZodString, ZodAny>>; paint: ZodOptional<ZodObject<{ background-color: ZodOptional<ZodUnion<[ZodEffects<ZodString, string, string>, ZodType<…[], ZodTypeDef, …[]>]>>; background-opacity: ZodOptional<ZodUnion<[ZodNumber, ZodType<…[], ZodTypeDef, …[]>]>>; background-pattern: ZodOptional<ZodUnion<[ZodString, ZodType<…[], ZodTypeDef, …[]>]>>; }, "passthrough", ZodTypeAny, objectOutputType<{ background-color: ZodOptional<ZodUnion<[ZodEffects<…, …, …>, ZodType<…, …, …>]>>; background-opacity: ZodOptional<ZodUnion<[ZodNumber, ZodType<…, …, …>]>>; background-pattern: ZodOptional<ZodUnion<[ZodString, ZodType<…, …, …>]>>; }, ZodTypeAny, "passthrough">, objectInputType<{ background-color: ZodOptional<ZodUnion<[ZodEffects<…, …, …>, ZodType<…, …, …>]>>; background-opacity: ZodOptional<ZodUnion<[ZodNumber, ZodType<…, …, …>]>>; background-pattern: ZodOptional<ZodUnion<[ZodString, ZodType<…, …, …>]>>; }, ZodTypeAny, "passthrough">>>; type: ZodLiteral<"background">; }, ZodTypeAny, "passthrough">
beforeId?string
options?LayerAddOptions

Promise<void>


replaceSource(sourceId, next): void

Defined in: packages/core/src/renderer/layer-manager.ts:1009

Rebuild a named source from the next document’s spec (live documents, KTD4): for a change MapLibre has no setter for, or a setter the running maplibre-gl lacks. The document layers over it are taken off the map (their slot remembered, see parkedAnchors) for the caller to add again through replaceLayer; the source is removed and registered anew, so a url: fetches again. Refused — nothing changes — while a layer the document did not declare still draws it.

ParameterType
sourceIdstring
nextRecord<string, unknown>

void


resume(): void

Defined in: packages/core/src/renderer/layer-manager.ts:2097

The counterpart of pause: the rebuild failed and this map stays.

void


resumeRefresh(layerId): void

Defined in: packages/core/src/renderer/layer-manager.ts:2120

Resume data refresh for a layer (polling)

ParameterType
layerIdstring

void


retargetPipeline(sourceId, next, options?): Promise<void>

Defined in: packages/core/src/renderer/layer-manager.ts:916

Bring a GeoJSON source’s pipeline in line with the next document’s config (live documents, U3), touching only what changed: an interval change reschedules the running poll; a change to what the poll captured (URL, cache, merge options) restarts it; refresh removed stops it, added starts it; a stream change reconnects; a FlatGeobuf or GeoParquet source whose reader options changed gets a new reader. A merge-strategy change drops the features accumulated under the old strategy and fetches at once, so the map never shows a mix.

ParameterTypeDescription
sourceIdstring-
nextRecord<string, unknown>-
options{ reload?: boolean; }-
options.reload?booleanFetch the URL again now (it changed, or its last load failed) and setData the response if it is still current.

Promise<void>


setLayerProperty(layerId, target, property, value): void

Defined in: packages/core/src/renderer/layer-manager.ts:1152

Set one live-settable property of a document layer (live documents, U2): paint, layout, filter (undefined clears), zoom (minzoom / maxzoom; undefined restores the layer defaults) or visibility. Values are the next document’s; nothing is read back from the map (R10). Host layers — anything this manager did not add — are never touched (KTD1), as moveLayer never moves them.

ParameterType
layerIdstring
target"filter" | "visibility" | "zoom" | "paint" | "layout"
propertystring
valueunknown

void


setNamedSourcesNeedingIds(ids): void

Defined in: packages/core/src/renderer/layer-manager.ts:456

The named sources a highlighted layer draws from, for the next document (live documents): registerSources reads this set when a source is added or rebuilt, so an update that adds hover.highlight over a named source — which the differ answers with a generateId replacement — gets feature ids on the rebuilt source, not the first document’s answer.

ParameterType
idsReadonlySet<string>

void


setSourceData(sourceId, data): void

Defined in: packages/core/src/renderer/layer-manager.ts:829

Replace a GeoJSON source’s data in place (live documents, U3): an inline data: edit, or a named source’s. Layers over it hear data-loaded as they do after a refresh, so classify breaks and the host’s feature-state reset follow the new data.

ParameterType
sourceIdstring
dataFeatureCollection

void


setSourceTiles(sourceId, next): boolean

Defined in: packages/core/src/renderer/layer-manager.ts:891

Point a tile source at other tile URLs in place through setTiles (live documents, KTD4), resolved as on first render.

ParameterType
sourceIdstring
nextRecord<string, unknown>

boolean

false when the running maplibre-gl has no setTiles on this source (RasterTileSource gained it in 3.5): the caller replaces the source instead.


setSourceUrl(sourceId, next): Promise<boolean>

Defined in: packages/core/src/renderer/layer-manager.ts:848

Point a source at another URL in place (live documents, KTD4). A GeoJSON source is fetched again through the same path first render uses and setData applied when the response is still current; its live-data pipeline is re-targeted. A tile, image or video source goes through MapLibre’s own setter.

ParameterType
sourceIdstring
nextRecord<string, unknown>

Promise<boolean>

false when the running maplibre-gl has no setter for this source (RasterTileSource gained setUrl in 4.0): the caller replaces the source instead.


settleSources(): string[]

Defined in: packages/core/src/renderer/layer-manager.ts:653

Apply the releases held since beginSourceSettlement. Returns the named sources whose count reached zero: their pipelines are stopped, their MapLibre source is left for the caller (see removeSource).

string[]


setVisibility(layerId, visible): void

Defined in: packages/core/src/renderer/layer-manager.ts:2187

ParameterType
layerIdstring
visibleboolean

void


sourceRefCount(sourceId): number

Defined in: packages/core/src/renderer/layer-manager.ts:674

How many document layers draw a named source (pending releases not yet subtracted).

ParameterType
sourceIdstring

number


updateData(layerId, data): void

Defined in: packages/core/src/renderer/layer-manager.ts:2196

ParameterType
layerIdstring
dataGeoJSON

void


wholeColumns(sourceId, names): Promise<FeatureCollection<Geometry, GeoJsonProperties>> | undefined

Defined in: packages/core/src/renderer/layer-manager.ts:1805

Whole columns of a source read by view, for computed classify breaks (0.10 U3): a GeoParquet source’s canonical rows, from the file its reader opened; undefined when its reader can’t (FlatGeobuf) or it isn’t read by view.

ParameterType
sourceIdstring
namesreadonly string[]

Promise<FeatureCollection<Geometry, GeoJsonProperties>> | undefined