LayerManager
Defined in: packages/core/src/renderer/layer-manager.ts:316
Manages map layers and their data sources
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new LayerManager(
map,callbacks?,data?):LayerManager
Defined in: packages/core/src/renderer/layer-manager.ts:430
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
map | maplibregl.Map |
callbacks? | LayerManagerCallbacks |
data? | LayerManagerDataOptions |
Returns
Section titled “Returns”LayerManager
Properties
Section titled “Properties”tileJsonFailed
Section titled “tileJsonFailed”
readonlytileJsonFailed: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.
Methods
Section titled “Methods”addLayer()
Section titled “addLayer()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layer | 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<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 |
Returns
Section titled “Returns”Promise<void>
beginSourceSettlement()
Section titled “beginSourceSettlement()”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.
Returns
Section titled “Returns”void
destroy()
Section titled “destroy()”destroy():
void
Defined in: packages/core/src/renderer/layer-manager.ts:2207
Returns
Section titled “Returns”void
disconnectStream()
Section titled “disconnectStream()”disconnectStream(
layerId):void
Defined in: packages/core/src/renderer/layer-manager.ts:2153
Disconnect streaming connection for a layer
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layerId | string |
Returns
Section titled “Returns”void
failedSources()
Section titled “failedSources()”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.
Returns
Section titled “Returns”ReadonlySet<string>
getGrid()
Section titled “getGrid()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
Returns
Section titled “Returns”GridField | undefined
getSourceData()
Section titled “getSourceData()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
Returns
Section titled “Returns”FeatureCollection<Geometry, GeoJsonProperties> | undefined
getSourceExtent()
Section titled “getSourceExtent()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
Returns
Section titled “Returns”[[number, number], [number, number]] | undefined
getSourceIdForLayer()
Section titled “getSourceIdForLayer()”getSourceIdForLayer(
layerId):string|undefined
Defined in: packages/core/src/renderer/layer-manager.ts:577
The MapLibre source a layer draws from.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layerId | string |
Returns
Section titled “Returns”string | undefined
getViewMinzoom()
Section titled “getViewMinzoom()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
Returns
Section titled “Returns”number | undefined
getViewZoomThatFits()
Section titled “getViewZoomThatFits()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
center | [number, number] |
from | number |
width | number |
height | number |
Returns
Section titled “Returns”number | undefined
gridReady()
Section titled “gridReady()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
Returns
Section titled “Returns”Promise<GridField>
hasGrid()
Section titled “hasGrid()”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).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
Returns
Section titled “Returns”boolean
hintOnce()
Section titled “hintOnce()”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).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layerId | string |
anchor | string |
message | string |
Returns
Section titled “Returns”void
isRefreshing()
Section titled “isRefreshing()”isRefreshing(
sourceId):boolean
Defined in: packages/core/src/renderer/layer-manager.ts:1074
Whether a refresh/stream pipeline is running for a named source.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
Returns
Section titled “Returns”boolean
moveLayer()
Section titled “moveLayer()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layerId | string |
beforeId? | string |
Returns
Section titled “Returns”void
ownsLayer()
Section titled “ownsLayer()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layerId | string |
Returns
Section titled “Returns”boolean
pause()
Section titled “pause()”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.
Returns
Section titled “Returns”void
pauseRefresh()
Section titled “pauseRefresh()”pauseRefresh(
layerId):void
Defined in: packages/core/src/renderer/layer-manager.ts:2113
Pause data refresh for a layer (polling)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layerId | string |
Returns
Section titled “Returns”void
readerToken()
Section titled “readerToken()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
Returns
Section titled “Returns”object | undefined
readsByView()
Section titled “readsByView()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
Returns
Section titled “Returns”boolean
recreateLoader()
Section titled “recreateLoader()”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).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
next | Record<string, unknown> |
Returns
Section titled “Returns”Promise<void>
refreshNow()
Section titled “refreshNow()”refreshNow(
layerId):Promise<void>
Defined in: packages/core/src/renderer/layer-manager.ts:2129
Force immediate refresh for a layer (polling)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layerId | string |
Returns
Section titled “Returns”Promise<void>
Throws
Section titled “Throws”when the layer has no poll running (as PollingManager.triggerNow does).
registerSources()
Section titled “registerSources()”registerSources(
sources):void
Defined in: packages/core/src/renderer/layer-manager.ts:470
Register the block’s named sources: with MapLibre.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sources | Record<string, unknown> |
Returns
Section titled “Returns”void
Remarks
Section titled “Remarks”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()
Section titled “removeLayer()”removeLayer(
layerId):void
Defined in: packages/core/src/renderer/layer-manager.ts:2157
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layerId | string |
Returns
Section titled “Returns”void
removeSource()
Section titled “removeSource()”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).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
Returns
Section titled “Returns”void
replaceLayer()
Section titled “replaceLayer()”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).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layer | 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<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 |
Returns
Section titled “Returns”Promise<void>
replaceSource()
Section titled “replaceSource()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
next | Record<string, unknown> |
Returns
Section titled “Returns”void
resume()
Section titled “resume()”resume():
void
Defined in: packages/core/src/renderer/layer-manager.ts:2097
The counterpart of pause: the rebuild failed and this map stays.
Returns
Section titled “Returns”void
resumeRefresh()
Section titled “resumeRefresh()”resumeRefresh(
layerId):void
Defined in: packages/core/src/renderer/layer-manager.ts:2120
Resume data refresh for a layer (polling)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layerId | string |
Returns
Section titled “Returns”void
retargetPipeline()
Section titled “retargetPipeline()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
sourceId | string | - |
next | Record<string, unknown> | - |
options | { reload?: boolean; } | - |
options.reload? | boolean | Fetch the URL again now (it changed, or its last load failed) and setData the response if it is still current. |
Returns
Section titled “Returns”Promise<void>
setLayerProperty()
Section titled “setLayerProperty()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layerId | string |
target | "filter" | "visibility" | "zoom" | "paint" | "layout" |
property | string |
value | unknown |
Returns
Section titled “Returns”void
setNamedSourcesNeedingIds()
Section titled “setNamedSourcesNeedingIds()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ids | ReadonlySet<string> |
Returns
Section titled “Returns”void
setSourceData()
Section titled “setSourceData()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
data | FeatureCollection |
Returns
Section titled “Returns”void
setSourceTiles()
Section titled “setSourceTiles()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
next | Record<string, unknown> |
Returns
Section titled “Returns”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()
Section titled “setSourceUrl()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
next | Record<string, unknown> |
Returns
Section titled “Returns”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()
Section titled “settleSources()”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).
Returns
Section titled “Returns”string[]
setVisibility()
Section titled “setVisibility()”setVisibility(
layerId,visible):void
Defined in: packages/core/src/renderer/layer-manager.ts:2187
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layerId | string |
visible | boolean |
Returns
Section titled “Returns”void
sourceRefCount()
Section titled “sourceRefCount()”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).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
Returns
Section titled “Returns”number
updateData()
Section titled “updateData()”updateData(
layerId,data):void
Defined in: packages/core/src/renderer/layer-manager.ts:2196
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
layerId | string |
data | GeoJSON |
Returns
Section titled “Returns”void
wholeColumns()
Section titled “wholeColumns()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sourceId | string |
names | readonly string[] |
Returns
Section titled “Returns”Promise<FeatureCollection<Geometry, GeoJsonProperties>> | undefined