CanvasSource
Defined in: src/source/canvas_source.ts:66
A data source containing the contents of an HTML canvas. See CanvasSourceSpecification for detailed documentation of options.
Example
// add to map
map.addSource('some id', {
type: 'canvas',
canvas: 'idOfMyHTMLCanvas',
animate: true,
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
Extends
Methods
getCanvas()
getCanvas():
HTMLCanvasElement
Defined in: src/source/canvas_source.ts:145
Returns the HTML canvas
element.
Returns
HTMLCanvasElement
The HTML canvas
element.
listens()
listens(
type
:string
):boolean
Defined in: src/util/evented.ts:165
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
loaded()
loaded():
boolean
Defined in: src/source/image_source.ts:150
True if the source is loaded, false otherwise.
Returns
boolean
Inherited from
loadTile()
loadTile(
tile
:Tile
):Promise
<void
>
Defined in: src/source/image_source.ts:258
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(
type
:string
,listener
:Listener
):CanvasSource
Defined in: src/util/evented.ts:90
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
Inherited from
on()
on(
type
:string
,listener
:Listener
):Subscription
Defined in: src/util/evented.ts:73
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
Inherited from
once()
once(
type
:string
,listener
?:Listener
):Promise
<any
> |CanvasSource
Defined in: src/util/evented.ts:106
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
> | CanvasSource
this
or a promise if a listener is not provided
Inherited from
setCoordinates()
setCoordinates(
coordinates
:Coordinates
):this
Defined in: src/source/image_source.ts:202
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
,data
?:any
):CanvasSource
Defined in: src/util/evented.ts:176
Bubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters
Parameter | Type |
---|---|
parent ? |
Evented |
data ? |
any |
Returns
Inherited from
updateImage()
updateImage(
options
:UpdateImageOptions
):this
Defined in: src/source/image_source.ts:160
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
Properties
id
id:
string
Defined in: src/source/image_source.ts:86
The id for the source. Must not be used by any existing source.
Inherited from
maxzoom
maxzoom:
number
Defined in: src/source/image_source.ts:88
The maximum zoom level for the source.
Inherited from
minzoom
minzoom:
number
Defined in: src/source/image_source.ts:87
The minimum zoom level for the source.
Inherited from
pause()
pause: () =>
void
Defined in: src/source/canvas_source.ts:79
Disables animation. The map will display a static copy of the canvas image.
Returns
void
play()
play: () =>
void
Defined in: src/source/canvas_source.ts:75
Enables animation. The image will be copied from the canvas to the map on each frame.
Returns
void
tileSize
tileSize:
number
Defined in: src/source/image_source.ts:89
The tile size for the source.