Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Maplibre Gl Js Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-maplibre-gl-js-knowledge-patch)
---
name: maplibre-gl-js-knowledge-patch
description: MapLibre GL JS
version: "6.20.0"
license: MIT
metadata:
author: Nevaberry
---
# MapLibre GL JS Knowledge Patch
Load this skill when migrating MapLibre GL JS code or working on map startup,
workers, events, sources, styles, camera behavior, globe rendering, or terrain.
Use the topic references for detailed behavior, examples, and release attribution.
> [!CAUTION]
> Guidance marked as prerelease in the references may change before stable release.
## Reference index
| Reference | Topics |
| --- | --- |
| [Runtime and migration](references/runtime-and-migration.md) | ESM, WebGL, workers, CSP, browser startup, sanitization, legacy APIs |
| [Events and controls](references/events-and-controls.md) | Subscriptions, event types, loading, errors, geolocation, markers, popups |
| [Camera, globe, and terrain](references/camera-globe-and-terrain.md) | Projections, coordinates, bounds, gestures, elevation, camera animations |
| [Sources, data, and requests](references/sources-data-and-requests.md) | GeoJSON, clustering, vector tiles, raster DEMs, images, request transforms, protocols |
| [Style and custom rendering](references/style-and-custom-rendering.md) | Validation, state, transitions, images, custom layers, fonts, symbols, paint properties |
## Breaking changes and deprecations
### ESM imports and worker deployment
The package ships `maplibre-gl.mjs` as an ES module and drops the
`maplibre-gl.js` and `maplibre-gl-csp.js` UMD bundles. Use named or namespace
imports and load direct browser imports from a `<script type="module">`.
```js
import * as maplibregl from 'maplibre-gl';
```
In a bundled app, call `setWorkerUrl()` once before creating maps. Point it
to the emitted or self-hosted `maplibre-gl-worker.mjs` file.
```js
import {setWorkerUrl} from 'maplibre-gl';
setWorkerUrl('/assets/maplibre-gl-worker.mjs');
```
With a direct worker URL, allow that URL in `worker-src` and drop the old
`blob:` allowance required by the UMD bundle. When the browser imports
MapLibre from a CDN on another origin, the worker starts from a same-origin
Blob URL; allow `blob:` in `worker-src` for that setup. Keep `data:` and
`blob:` in `img-src`, including when self-hosting the worker.
Use an explicit major version in direct CDN imports, such as
`maplibre-gl@^6.0.0/dist/maplibre-gl.mjs`. An unversioned v5 script URL or one
using `@latest` can return a 404 and leave the map blank when it resolves to v6.
In 6.13.0, the worker bundle is self-contained and its default URL includes
a versioned `v` query parameter. Remove `maplibre-gl-shared.mjs` and
`maplibre-gl-shared-dev.mjs` from deployment copy steps when upgrading to
6.13.0 or later. Both files are empty and deprecated, with removal planned
for the next major version.
### Runtime and WebGL startup
The build targets ES2022. If supporting older runtimes or tooling,
transpile the dependency or update the affected tooling.
Map creation requires WebGL 2. From 6.7.0, failed WebGL 2 context creation
throws `GPUInitializationError` synchronously from the `Map` constructor;
wrap that constructor call in `try`/`catch` to handle the startup failure.
Move `antialias`, `preserveDrawingBuffer`, and `failIfMajorPerformanceCaveat`
into `MapOptions.canvasContextAttributes`.
### Event subscriptions and types
`map.on()` returns a `Subscription`. Register each listener in a separate
call and use `unsubscribe()` on the returned subscription to remove it.
```js
const subscription = map.on('moveend', onMoveEnd);
map.on('zoomend', onZoomEnd);
subscription.unsubscribe();
```
Use `MapBoxZoomEvent` in place of `MapLibreZoomEvent`, and
`MapSourceDataEvent | MapStyleDataEvent` in place of `MapDataEvent` for
`data`, `dataloading`, and `dataabort`. Check the event's `type` field to
distinguish variants in shared handlers. Augment the `maplibre-gl` module's
`MapEventType` interface to type application-defined event payloads.
### GeoJSON updates and tile overscaling
In v6, call `source.setData(data)` with one argument. The `waitForCompletion`
flag was removed, and `setData()` no longer returns the source for chaining.
Nested GeoJSON feature properties round-trip as objects; encoded values
read directly can contain the `__$json__` prefix used before decoding.
`zoomLevelsToOverscale` defaults to `4`, which can change
`queryRenderedFeatures()` results and polygon center label placement.
Set `zoomLevelsToOverscale: undefined` to restore the previous behavior.
### Missing style images
`styleimagemissing` only reports a missing image. Register a synchronous or
asynchronous callback with `map.setMissingStyleImageResolver(resolveImage)`.
The resolver receives the image ID as a string. For asynchronous loading,
call `map.addImage(id, image)` before the resolver's promise settles.
```js
map.setMissingStyleImageResolver(async (id) => {
const image = await loadImageForId(id);
map.addImage(id, image);
});
```
From 6.4.0, replacing a style sprite removes the old sprite's images.
Layers still referencing those IDs need the replacement sprite or
application to supply them.
### Custom code and style migration
Replace direct uses of `map.transform` with public map methods and update
code relying on the removed `transform.getMatrixForModel()`.
`StyleLayer.queryIntersectsFeature()` takes one `QueryIntersectsFeatureParams`
object; migrate positional arguments to named fields. Replace `#pragma mapbox`
with `#pragma maplibre` in custom shaders using these directives.
Paint and layout getters and setters use actual property types in TypeScript.
Update callers relying on unrestricted property names or values.
Icon offsets no longer scale with icon size; check styles combining
`icon-offset` and `icon-size`.
From 6.9.0, Arabic and Hebrew labels render without an RTL text plugin.
`setRTLTextPlugin()` and `getRTLTextPluginStatus()` are deprecated.
In 6.15.0, replace deprecated `aroundCenter` with
`dragRotate: {around: 'center', movement: 'circular'}` or use
`movement: 'linear'` for linear drag motion.
## Sources and request handling
Set `encoding: 'mlt'` on a vector source whose tiles use MapLibre Tiles
encoding. From 6.16.0, MLT requests include an `Accept` header based on the
client's MLT capabilities. In 6.17.0, the experimental `sparse: true`
vector-source option fills missing tiles by slicing an ancestor tile.
From 6.12.0, `setData()` supersedes pending results from earlier URL loads
and `updateData()` calls; removing a source discards its waiting updates.
From 6.16.0, when a later `updateData()` re-adds a feature, an earlier queued
edit to that feature does not carry over.
`map.setTransformRequest()` accepts async callbacks. A request transform
can return `{url, referrerPolicy: 'no-referrer'}` for a tile request to omit
its `Referer` header. `map.setTransformRequest(null)` clears the transform.
Fetch failures such as CORS, DNS, and malformed URLs surface as an
`AJAXError` on the map's `error` event, with details on `event.error`.
## Style state, fonts, and rendering
Supported layout properties, `layout.visibility`, properties under `sky`
and `light`, and `projection.type` can read `global-state` expressions.
In 6.14.0, pass `globalState` when constructing a map or setting its style
to override defaults for the supplied style state keys. From 6.11.0,
transitionable paint, light, or sky properties reading `global-state`
animate from their prior values when the state changes.
`line-dasharray` can select dash patterns from feature properties. Wrap
each array returned by a `match` expression in `literal`.
`line-opacity` and alpha in `line-color` still compound at overlapping
strokes; use `line-layer-opacity` to keep intersections from darkening.
Use style `font-faces` for complex-script fonts; read or set it with
`map.getFontFaces()` and `map.setFontFaces()`. A style without a root
`glyphs` URL renders labels locally and treats `text-font` as a fallback
list. With a glyph URL configured, missing glyph files or characters also
trigger a local rendering attempt. Self-hosted glyph PBFs need the
supplementary-plane ranges required by labels above U+FFFF.
In 6.13.0, the experimental `CustomLayerInterface.renderToTerrainTile`
hook lets custom layers drape drawings over terrain, with
`terrainTileRevision` signaling changes. The `prerender` options expose
`renderTerrainHeightMap` for placing objects on terrain on the GPU.
In 6.15.0, experimental `addProjection()` and `removeProjection()` manage
custom planar coordinate reference systems with their own quad tile grids.
## Camera, globe, and interaction
`map.queryTerrainElevation(lngLat)` returns actual terrain altitude.
Subtract the altitude at a reference point for relative height. With
terrain enabled, `map.project()` and `map.queryTerrainElevation()` use
elevations consistent with the rendered surface.
In 6.12.0, pass `absolutePadding: true` to `cameraForBounds()` or
`fitBounds()` to use supplied `padding` as total persistent padding.
From 6.16.0, `map.setMaxBounds()` can constrain latitude or longitude
independently. From 6.19.0, those bounds can span a full 360° of longitude.
In 6.11.0, `map.calculateAnchoredCameraOptions()` computes options that
place a geographic location at a chosen screen position without changing
the current view. From 6.9.1, `map.project()` places locations behind the
camera outside the viewport on the side where they left the screen,
also moving associated DOM markers and popups off-screen.
Set `reduceMotion: true` in map constructor options for reduced motion.
From 6.14.0, `flyTo()` honors `offset` and `around` under
`prefers-reduced-motion`, so reduced-motion and animated paths land at
the same camera.
In 6.12.0, `new GeolocateControl({trackUserLocation: true, zoomToUserAccuracy: false})`
follows position updates without adjusting zoom to the reported accuracy.
`GeolocateControl` requires `trackUserLocation: true` to emit
`outofmaxbounds` for a location outside the map's maximum bounds.