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
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
fire()
Call Signature
fire(
event:ErrorEvent|MapSourceDataEvent):this
Calls every listener registered for the event's type.
Parameters
| Parameter | Type |
|---|---|
event |
ErrorEvent | MapSourceDataEvent
|
Returns
this
Inherited from
Call Signature
fire(
type: keyofSourceEventType,properties?:object):this
Compatibility with the (type: string, properties: Object) signature from previous versions. See https://github.com/mapbox/mapbox-gl-js/issues/6522, https://github.com/mapbox/mapbox-gl-draw/issues/766
Parameters
| Parameter | Type |
|---|---|
type | keyof SourceEventType
|
properties? | object |
Returns
this
Inherited from
getVideo()
getVideo():
HTMLVideoElement
Returns the HTML video element.
Returns
HTMLVideoElement
The HTML video element.
getWarp()
getWarp():
ImageSourceWarp
Experimental
Returns how the image is warped onto its coordinates.
Returns
The warp in use, see ImageSourceWarp.
Inherited from
listens()
listens(
type: keyofSourceEventType):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 | keyof SourceEventType
| The event type |
Returns
boolean
true if there is at least one registered listener for specified event type, false otherwise
Inherited from
loaded()
loaded():
boolean
True if the source is loaded, false otherwise.
Returns
boolean
Inherited from
loadTile()
loadTile(
tile:Tile):Promise<void>
This method does the heavy lifting of loading a tile. In most cases it will defer the work to the relevant worker source.
Parameters
| Parameter | Type | Description |
|---|---|---|
tile | Tile | The tile to load |
Returns
Promise<void>
Inherited from
off()
off<
Textends keyofSourceEventType>(type:T,listener: (event:SourceEventType[T]) =>void):this
Removes a previously registered event listener.
Type Parameters
| Type Parameter |
|---|
T extends keyof SourceEventType
|
Parameters
| Parameter | Type | Description |
|---|---|---|
type | T | The event type to remove listeners for. |
listener | (event: SourceEventType[T]) => void
| The listener function to remove. |
Returns
this
Inherited from
on()
on<
Textends keyofSourceEventType>(type:T,listener: (event:SourceEventType[T]) =>void):Subscription
Adds a listener to a specified event type.
Type Parameters
| Type Parameter |
|---|
T extends keyof SourceEventType
|
Parameters
| Parameter | Type | Description |
|---|---|---|
type | T | The event type to add a listen for. |
listener | (event: SourceEventType[T]) => void
| 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
Inherited from
once()
Call Signature
once<
Textends keyofSourceEventType>(type:T):Promise<SourceEventType[T]>
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.
Type Parameters
| Type Parameter |
|---|
T extends keyof SourceEventType
|
Parameters
| Parameter | Type | Description |
|---|---|---|
type | T | The event type to listen for. |
Returns
Promise<SourceEventType[T]>
a promise that resolves with the event
Inherited from
Call Signature
once<
Textends keyofSourceEventType>(type:T,listener: (event:SourceEventType[T]) =>void):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.
Type Parameters
| Type Parameter |
|---|
T extends keyof SourceEventType
|
Parameters
| Parameter | Type | Description |
|---|---|---|
type | T | The event type to listen for. |
listener | (event: SourceEventType[T]) => void
| The function to be called when the event is fired the first time. |
Returns
this
this when a listener is provided
Inherited from
pause()
pause():
void
Pauses the video.
Returns
void
play()
play():
void
Plays the video.
Returns
void
prepare()
prepare():
this
Sets the video's coordinates and re-renders the map.
Returns
this
Overrides
seek()
seek(
seconds:number):void
Sets playback to a timestamp, in seconds.
Parameters
| Parameter | Type |
|---|---|
seconds | number |
Returns
void
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
setEventedParent()
setEventedParent(
parent?:Evented<EventTypeMap>,data?:EventedParentData| (() =>EventedParentData)):this
Bubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
| Parameter | Type |
|---|---|
parent? |
Evented<EventTypeMap> |
data? |
EventedParentData | (() => EventedParentData) |
Returns
this
Inherited from
setWarp()
setWarp(
warp:ImageSourceWarp):this
Experimental
Sets how the image is warped onto its coordinates and re-renders the map.
This only has an effect while the coordinates do not form a rectangle, and it is not part of the style specification, so it does not survive map.setStyle.
Parameters
| Parameter | Type | Description |
|---|---|---|
warp | ImageSourceWarp | The warp to use, see ImageSourceWarp. |
Returns
this
Example
// Keep the image pinned to its corners while the user drags them around.
map.getSource('some id').setWarp('flat');
Inherited from
updateImage()
updateImage(
options:UpdateImageOptions):this
Updates the image 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.
Provide exactly one of url (to fetch a new image over the network) or image (an already-decoded HTMLImageElement, HTMLCanvasElement, ImageBitmap or ImageData to display directly, without a network request).
Parameters
| Parameter | Type | Description |
|---|---|---|
options | UpdateImageOptions | The options object. |
Returns
this
Inherited from
Properties
id
id:
string
The id for the source. Must not be used by any existing source.
Inherited from
maxzoom
maxzoom:
number
The maximum zoom level for the source.
Inherited from
minzoom
minzoom:
number
The minimum zoom level for the source.
Inherited from
terrainTileRanges
terrainTileRanges:
object
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.
Index Signature
[zoom: string]: CanonicalTileRange
Inherited from
tileSize
tileSize:
number
The tile size for the source.
Inherited from
© MapLibre contributors
Licensed under the 3-Clause BSD License.
https://maplibre.org/maplibre-gl-js/docs/API/classes/VideoSource/