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

getSource

Quick answer

getSource < TSource extends Source >( id : string ): TSource

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

getSource<TSource extends Source>(id: string): TSource

Defined in: ui/map.ts:3132

Returns the source with the specified ID in the map's style.

This method is often used to update a source using the instance members for the relevant source type as defined in classes that derive from Source. For example, setting the data for a GeoJSON source or updating the url and coordinates of an image source.

Type Parameters

Type Parameter
TSource extends Source

Parameters

Parameter Type Description
id string The ID of the source to get.

Returns

TSource

The style source with the specified ID or undefined if the ID corresponds to no existing sources. The shape of the object varies by source type. A list of options for each source type is available on the MapLibre Style Specification's Sources page.

Example

let sourceObject = map.getSource('points');

See


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/get-source.html
Cite this page

Atlaslog (2026). getSource. https://www.jingweizhi.com/en/maplibre/api/get-source.html (accessed 2026-11-03).