On this page

Class VideoSource

A data source containing video. (See the Style Specification for detailed documentation of options.)

// add to map
map.addSource('some id', {
   type: 'video',
   url: [
       'https://www.mapbox.com/blog/assets/baltimore-smoke.mp4',
       'https://www.mapbox.com/blog/assets/baltimore-smoke.webm'
   ],
   coordinates: [
       [-76.54, 39.18],
       [-76.52, 39.18],
       [-76.52, 39.17],
       [-76.54, 39.17]
   ]
});

// update
let mySource = map.getSource('some id');
mySource.setCoordinates([
    [-76.54335737228394, 39.18579907229748],
    [-76.52803659439087, 39.1838364847587],
    [-76.5295386314392, 39.17683392507606],
    [-76.54520273208618, 39.17876344106642]
]);

map.removeSource('some id');  // remove

Add a video

Note that when rendered as a raster layer, the layer's raster-fade-duration property will cause the video to fade in. This happens when playback is started, paused and resumed, or when the video's coordinates are updated. To avoid this behavior, set the layer's raster-fade-duration property to 0.

Hierarchy (View Summary)

Index

Constructors

Properties

coordinates: Coordinates
dispatcher: Dispatcher
flippedWindingOrder: boolean
id: string

The id for the source. Must not be used by any existing source.

maxzoom: number

The maximum zoom level for the source.

minzoom: number

The minimum zoom level for the source.

roundZoom: boolean
terrainTileRanges: { [zoom: string]: CanonicalTileRange }

This object is used to store the range of terrain tiles that overlap with this tile. It is relevant for image tiles, as the image exceeds single tile boundaries.

texture: Texture | null
tileCoords: Point[]
tiles: { [_: string]: Tile }
tileSize: number

The tile size for the source.

type: string
url: string
urls: string[]

Methods

  • An ability to fire an event to all the listeners, see Evented

    Parameters

    • event: string | Event

      The event to fire

    • Optionalproperties: any

    Returns this

  • True if the source has transition, false otherwise.

    Returns boolean

  • Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.

    Parameters

    • type: string

      The event type

    Returns boolean

    true if there is at least one registered listener for specified event type, false otherwise

  • True if the source is loaded, false otherwise.

    Returns boolean

  • This method does the heavy lifting of loading a tile. In most cases it will defer the work to the relevant worker source.

    Parameters

    • tile: Tile

      The tile to load

    Returns Promise<void>

  • Removes a previously registered event listener.

    Parameters

    • type: string

      The event type to remove listeners for.

    • listener: Listener

      The listener function to remove.

    Returns this

  • Adds a listener to a specified event type.

    Parameters

    • type: string

      The event type to add a listen for.

    • listener: Listener

      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 Subscription

  • 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

    • type: string

      The event type to listen for.

    • Optionallistener: Listener

      The function to be called when the event is fired the first time.

    Returns VideoSource | Promise<any>

    this or a promise if a listener is not provided

  • This method is called when the source is removed from the map.

    Returns void

  • Pauses the video.

    Returns void

  • Plays the video.

    Returns void

  • Sets the video's coordinates and re-renders the map.

    Returns this

  • Sets playback to a timestamp, in seconds.

    Parameters

    • seconds: number

    Returns void

  • Sets the image's coordinates and re-renders the map.

    Parameters

    • coordinates: 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 this

  • Bubble all events fired by this instance of Evented to this parent instance of Evented.

    Parameters

    • Optionalparent: Evented | null
    • Optionaldata: any

    Returns 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

    Returns this

Was this helpful?
SDK JS
Reference
VideoSource