Skip to Content
APIConfigurationFunction: setMapLibreWorkerUrl()

Function: setMapLibreWorkerUrl()

function setMapLibreWorkerUrl(url): void

Points MapLibre at a worker script you host yourself, instead of the one bundled into this SDK.

The bundled worker is delivered as a blob: URL, which a Content-Security-Policy without worker-src blob: (or child-src blob:) will block. Self-hosting is the way out: copy maplibre-gl-worker.mjs and maplibre-gl-shared.mjs from maplibre-gl/dist — the worker imports the shared file at runtime, so both must be served from the same directory — and point this at the first one. Use npm ls maplibre-gl to see which version this SDK resolved; the files must come from that one.

The URL has to be same-origin. A cross-origin one does not escape blob:: MapLibre wraps any worker URL it considers cross-origin in a generated blob: worker that imports it, so a CDN-hosted worker hits exactly the same Content-Security-Policy wall as the bundled one.

Call it before creating any map. Once MapLibre’s worker pool has spun up it does not re-read the URL until every map has been removed.

Exists so opting out does not force a direct maplibre-gl dependency on consumers that only use this SDK.

Parameters

url

string

URL of the MapLibre worker script to load.

Returns

void

Example

import { setMapLibreWorkerUrl, initializeSDK } from "@mapvx/web-js" setMapLibreWorkerUrl("/assets/maplibre-gl-worker.mjs") const sdk = initializeSDK(token)
Last updated on