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
        
      
      : 
      thisAdds 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
        
      
      : 
      thisBubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)(any)Returns
        
          VectorTileSource
        
      
      : 
      thisRelated 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
        
      
      : 
      thisAdds 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
        
      
      : 
      thisBubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)(any)Returns
        
          RasterTileSource
        
      
      : 
      thisRelated 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[]>
      Allows getting the source's boundaries. If there's a problem with the source's data, it will return an empty LngLatBounds.
Returns
          Promise<LngLatBounds>
        
        : 
        A promise which resolves to the source's boundaries.
      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
Allows to get the source's actual GeoJSON data.
Returns
A promise which resolves to the source's actual GeoJSON data.Promise <
        GeoJSON >
      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
        
      
      : 
      thisAdds 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
        
      
      : 
      thisBubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)(any)Returns
        
          GeoJSONSource
        
      
      : 
      thisThis method does the heavy lifting of loading a tile. In most cases it will defer the work to the relevant worker source.
Parameters
Returns
Promise<void[]>
      This method returns a plain (stringifiable) JS object representing the current state of the source. Creating a source using the returned object as the options should result in a Source that is equivalent to this one.
Returns
GeoJSONSourceSpecification
      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
          
      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
        
      
      : 
      thisAdds 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
        
      
      : 
      thisBubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)(any)Returns
        
          RasterDEMTileSource
        
      
      : 
      thisSets 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
        
      
      : 
      thisAdds 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
        
      
      : 
      thisBubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)(any)Returns
        
          ImageSource
        
      
      : 
      thisSets 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
        
      
      : 
      thisAdds 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
        
      
      : 
      thisBubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)(any)Returns
        
          VideoSource
        
      
      : 
      thisPauses 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 HTMLCanvasElementitself. | 
| 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), animateshould be set tofalseto 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
        
      
      : 
      thisAdds 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
        
      
      : 
      thisBubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
(Evented)(any)Returns
        
          CanvasSource
        
      
      : 
      thisDisables 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