getSource<
TSourceextendsSource>(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
- Create a draggable point
- Animate a point
- Add live realtime data