Sources
A source provides the data that is displayed on a map. Sources are defined by the GL Style Specification.
Vector Tile
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
Methods
Returns a true if this instance of Evented or any forwarded instances of Evented has a listener for the specified type.
boolean
:
true
if there is at least one registered listener
for specified event type, false
otherwise
Adds a listener to a specified event type.
Parameters
(Function)
The
function to be called when the event is fired.
The listener function is called with the data object passed to
fire
,
extended with
target
and
type
properties.
Returns
VectorTileSource
:
this
Adds a listener that will be called only once to a specified event type.
The listener will be called first time the event fires after the listener is registered.
Parameters
Returns
VectorTileSource
:
this
Bubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)
(any)
Returns
VectorTileSource
:
this
Related examples
Raster Tile
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
Methods
Returns a true if this instance of Evented or any forwarded instances of Evented has a listener for the specified type.
boolean
:
true
if there is at least one registered listener
for specified event type, false
otherwise
Adds a listener to a specified event type.
Parameters
(Function)
The
function to be called when the event is fired.
The listener function is called with the data object passed to
fire
,
extended with
target
and
type
properties.
Returns
RasterTileSource
:
this
Adds a listener that will be called only once to a specified event type.
The listener will be called first time the event fires after the listener is registered.
Parameters
Returns
RasterTileSource
:
this
Bubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)
(any)
Returns
RasterTileSource
:
this
Related examples
GeoJSON
A source containing GeoJSON. (See the Style Specification for detailed documentation of options.)
Example
Methods
Responsible for invoking WorkerSource's geojson.loadData target, which handles loading the geojson data and preparing to serve it up as tiles, using geojson-vt or supercluster as appropriate.
Parameters
(Callback<Array<GeoJSON.Feature>>)
A
callback to be called when the features are retrieved (
(error, features) => { ... }
).
Returns
Promise<void[]>
For clustered sources, fetches the children of the given cluster on the next zoom level (as an array of GeoJSON features).
Parameters
Returns
Promise<Feature<Geometry,{ [name: string]: any; }>[]>
:
A promise that is resolved when the features are retrieved.
For clustered sources, fetches the zoom at which the given cluster expands.
Parameters
Returns
Promise<number>
:
A promise that is resolved with the zoom number.
For clustered sources, fetches the original points that belong to the cluster (as an array of GeoJSON features).
Parameters
Returns
Promise<Feature<Geometry,{ [name: string]: any; }>[]>
:
A promise that is resolved when the features are retrieved.
Example
Returns a true if this instance of Evented or any forwarded instances of Evented has a listener for the specified type.
boolean
:
true
if there is at least one registered listener
for specified event type, false
otherwise
Adds a listener to a specified event type.
Parameters
(Function)
The
function to be called when the event is fired.
The listener function is called with the data object passed to
fire
,
extended with
target
and
type
properties.
Returns
GeoJSONSource
:
this
Adds a listener that will be called only once to a specified event type.
The listener will be called first time the event fires after the listener is registered.
Parameters
Returns
GeoJSONSource
:
this
Bubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)
(any)
Returns
GeoJSONSource
:
this
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
Updates the source's GeoJSON, and re-renders the map.
For sources with lots of features, this method can be used to make updates more quickly.
This approach requires unique IDs for every feature in the source. The IDs can either be specified on the feature, or by using the promoteId option to specify which property should be used as the ID.
It is an error to call updateData on a source that did not have unique IDs for each of its features already.
Updates are applied on a best-effort basis, updating an ID that does not exist will not result in an error.
Parameters
Returns
GeoJSONSource
:
this
Allows to get the source's actual GeoJSON data.
Returns
A promise which resolves to the source's actual GeoJSON data.Promise
<
GeoJSON
>
Related examples
Raster DEM Tile
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
Methods
Returns a true if this instance of Evented or any forwarded instances of Evented has a listener for the specified type.
boolean
:
true
if there is at least one registered listener
for specified event type, false
otherwise
Adds a listener to a specified event type.
Parameters
(Function)
The
function to be called when the event is fired.
The listener function is called with the data object passed to
fire
,
extended with
target
and
type
properties.
Returns
RasterDEMTileSource
:
this
Adds a listener that will be called only once to a specified event type.
The listener will be called first time the event fires after the listener is registered.
Parameters
Returns
RasterDEMTileSource
:
this
Bubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)
(any)
Returns
RasterDEMTileSource
:
this
Sets the source tiles
property and re-renders the map.
Parameters
Returns
RasterDEMTileSource
:
this
Related examples
Image
A data source containing an image. (See the Style Specification for detailed documentation of options.)
Example
Methods
Returns a true if this instance of Evented or any forwarded instances of Evented has a listener for the specified type.
boolean
:
true
if there is at least one registered listener
for specified event type, false
otherwise
Adds a listener to a specified event type.
Parameters
(Function)
The
function to be called when the event is fired.
The listener function is called with the data object passed to
fire
,
extended with
target
and
type
properties.
Returns
ImageSource
:
this
Adds a listener that will be called only once to a specified event type.
The listener will be called first time the event fires after the listener is registered.
Parameters
Returns
ImageSource
:
this
Bubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)
(any)
Returns
ImageSource
:
this
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
Returns a true if this instance of Evented or any forwarded instances of Evented has a listener for the specified type.
boolean
:
true
if there is at least one registered listener
for specified event type, false
otherwise
Adds a listener to a specified event type.
Parameters
(Function)
The
function to be called when the event is fired.
The listener function is called with the data object passed to
fire
,
extended with
target
and
type
properties.
Returns
VideoSource
:
this
Adds a listener that will be called only once to a specified event type.
The listener will be called first time the event fires after the listener is registered.
Parameters
Returns
VideoSource
:
this
Bubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)
(any)
Returns
VideoSource
:
this
Pauses the video.
Plays the video.
Sets the video'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
VideoSource
:
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
VideoSource
:
this
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
Returns a true if this instance of Evented or any forwarded instances of Evented has a listener for the specified type.
boolean
:
true
if there is at least one registered listener
for specified event type, false
otherwise
Adds a listener to a specified event type.
Parameters
(Function)
The
function to be called when the event is fired.
The listener function is called with the data object passed to
fire
,
extended with
target
and
type
properties.
Returns
CanvasSource
:
this
Adds a listener that will be called only once to a specified event type.
The listener will be called first time the event fires after the listener is registered.
Parameters
Returns
CanvasSource
:
this
Bubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)
(any)
Returns
CanvasSource
:
this
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.
Sets the video'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
CanvasSource
:
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
CanvasSource
:
this