Atlaslog
Atlaslog / MapLibre GL JS / API / removeLayer
MapLibre GL JS · API reference

removeLayer

Quick answer

removeLayer ( id : string ): this

Last verified 2026-11-03 · MapLibre GL JS 4.x · Cite this page
Runnable examplesChinese noteAll API topics
removeLayer()

removeLayer(id: string): this

Defined in: ui/map.ts:3577

Removes the layer with the given ID from the map's style.

An ErrorEvent will be fired if no such layer exists.

Parameters

Parameter Type Description
id string The ID of the layer to remove

Returns

this

Example

If a layer with ID 'state-data' exists, remove it.

if (map.getLayer('state-data')) map.removeLayer('state-data');


TutorialsAPI index
English reference text adapted from the official MapLibre GL JS documentation, © MapLibre contributors, licensed under BSD-3-Clause.
Original page: https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/ · Chinese note: /maplibre/api/remove-layer.html
Cite this page

Atlaslog (2026). removeLayer. https://www.jingweizhi.com/en/maplibre/api/remove-layer.html (accessed 2026-11-03).