Sources
A source provides the data that is displayed on a map. Sources are defined by the GL Style Specification.
Vector
src/source/vector_tile_source.ts
A vector tile source. Tiles must be in Vector Tile format. All layers that use a vector source must specify a "source-layer" value. (See the Style Specification for detailed documentation of options.)
Example
Related examples
Raster
src/source/raster_tile_source.ts
A raster tile source. Tiles must be in ZXY or TMS tile format. (See the Style Specification for detailed documentation of options.)
Example
Related examples
GeoJSON
A source containing GeoJSON. (See the Style Specification for detailed documentation of options.)
Example
Methods
For clustered sources, fetches the children of the given cluster on the next zoom level (as an array of GeoJSON features).
Parameters
(Callback<Array<GeoJSON.Feature>>)
A
callback to be called when the features are retrieved (
(error, features) => { ... }
).
Returns
GeoJSONSource
:
this
For clustered sources, fetches the zoom at which the given cluster expands.
Parameters
(Callback<number>)
A
callback to be called when the zoom value is retrieved (
(error, zoom) => { ... }
).
Returns
GeoJSONSource
:
this
For clustered sources, fetches the original points that belong to the cluster (as an array of GeoJSON features).
Parameters
(Callback<Array<GeoJSON.Feature>>)
A
callback to be called when the features are retrieved (
(error, features) => { ... }
).
Returns
GeoJSONSource
:
this
Example
Sets the GeoJSON data and re-renders the map.
Parameters
((Object | string))
A
GeoJSON data object or a URL to one. The latter is preferable in the case of large GeoJSON files.
Returns
GeoJSONSource
:
this
Related examples
Raster DEM
src/source/raster_dem_tile_source.ts
A raster DEM source. Only supports Terrain RGB format. (See the Style Specification for detailed documentation of options.)
Example
Related examples
Image
A data source containing an image. (See the Style Specification for detailed documentation of options.)
Example
Methods
Sets the image's coordinates and re-renders the map.
Parameters
(Array<Array<number>>)
Four
geographical coordinates,
represented as arrays of longitude and latitude numbers, which define the corners of the image.
The coordinates start at the top left corner of the image and proceed in clockwise order.
They do not have to represent a rectangle.
Returns
ImageSource
:
this
Updates the image URL and, optionally, the coordinates. To avoid having the image flash after changing,
set the raster-fade-duration
paint property on the raster layer to 0.
Parameters
(Object)
Options
object.
options.url | Required image URL. |
---|---|
options.coordinates | Four geographical coordinates, represented as arrays of longitude and latitude numbers, which define the corners of the image. The coordinates start at the top left corner of the image and proceed in clockwise order. They do not have to represent a rectangle. |
Returns
ImageSource
:
this
Video
A data source containing video. (See the Style Specification for detailed documentation of options.)
Example
Methods
Pauses the video.
Plays the video.
Related examples
Canvas
A data source containing the contents of an HTML canvas. See canvas source properties for detailed documentation of options.
Example
Properties
options.type |
Source type. Must be "canvas" .
|
---|---|
options.canvas |
Canvas source from which to read pixels. Can be a string representing the ID of the canvas element, or the
HTMLCanvasElement
itself.
|
options.coordinates |
Four geographical coordinates denoting where to place the corners of the canvas, specified in
[longitude, latitude]
pairs.
|
options.animate |
Whether the canvas source is animated. If the canvas is static (i.e. pixels do not need to be re-read on
every frame),
animate
should be set to
false
to improve performance.
|
Methods
Disables animation. The map will display a static copy of the canvas image.
Enables animation. The image will be copied from the canvas to the map on each frame.