Skip to content

VideoSource

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

Example

// 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

See

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.

Extends

Methods

getVideo()

getVideo(): HTMLVideoElement

Returns the HTML video element.

Returns

HTMLVideoElement

The HTML video element.

Source

src/source/video_source.ts:137


listens()

listens(type: string): boolean

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

Parameters

Parameter Type Description
type string The event type

Returns

boolean

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

Inherited from

ImageSource.listens

Source

src/util/evented.ts:161


off()

off(type: string, listener: Listener): VideoSource

Removes a previously registered event listener.

Parameters

Parameter Type Description
type string The event type to remove listeners for.
listener Listener The listener function to remove.

Returns

VideoSource

Inherited from

ImageSource.off

Source

src/util/evented.ts:86


on()

on(type: string, listener: Listener): this

Adds a listener to a specified event type.

Parameters

Parameter Type Description
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

this

Inherited from

ImageSource.on

Source

src/util/evented.ts:73


once()

once(type: string, listener?: Listener): Promise<any> | VideoSource

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

Parameter Type Description
type string The event type to listen for.
listener? Listener The function to be called when the event is fired the first time.

Returns

Promise<any> | VideoSource

this or a promise if a listener is not provided

Inherited from

ImageSource.once

Source

src/util/evented.ts:102


pause()

pause(): void

Pauses the video.

Returns

void

Source

src/source/video_source.ts:105


play()

play(): void

Plays the video.

Returns

void

Source

src/source/video_source.ts:114


prepare()

prepare(): this

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

Returns

this

Overrides

ImageSource.prepare

Source

src/source/video_source.ts:154


seek()

seek(seconds: number): void

Sets playback to a timestamp, in seconds.

Parameters

Parameter Type
seconds number

Returns

void

Source

src/source/video_source.ts:123


setCoordinates()

setCoordinates(coordinates: Coordinates): this

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

Parameters

Parameter Type Description
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

Inherited from

ImageSource.setCoordinates

Source

src/source/image_source.ts:207


setEventedParent()

setEventedParent(parent?: Evented, data?: any): VideoSource

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

Parameters

Parameter Type
parent? Evented
data? any

Returns

VideoSource

Inherited from

ImageSource.setEventedParent

Source

src/util/evented.ts:172


updateImage()

updateImage(options: UpdateImageOptions): 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

Parameter Type Description
options UpdateImageOptions The options object.

Returns

this

Inherited from

ImageSource.updateImage

Source

src/source/image_source.ts:165