Class: CanvasSource¶
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: [
[10.54, 106.18],
[10.52, 106.18],
[10.52, 106.17],
[10.54, 106.17]
]
});
// update
let mySource = map.getSource('some id');
mySource.setCoordinates([
[10.54335737228394, 106.18579907229748],
[10.52803659439087, 106.1838364847587],
[10.5295386314392, 106.17683392507606],
[10.54520273208618, 106.17876344106642]
]);
map.removeSource('some id'); // remove
Hierarchy¶
↳ CanvasSource
Methods¶
getCanvas¶
▸ getCanvas(): HTMLCanvasElement
Returns the HTML canvas
element.
Returns¶
HTMLCanvasElement
The HTML canvas
element.
Defined in¶
src/source/canvas_source.ts:147
listens¶
▸ listens(type
): boolean
Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
Parameters¶
Name | 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¶
Defined in¶
src/util/evented.ts:163
off¶
▸ off(type
, listener
): CanvasSource
Removes a previously registered event listener.
Parameters¶
Name | Type | Description |
---|---|---|
type |
string |
The event type to remove listeners for. |
listener |
Listener |
The listener function to remove. |
Returns¶
this
Inherited from¶
Defined in¶
src/util/evented.ts:88
on¶
▸ on(type
, listener
): this
Adds a listener to a specified event type.
Parameters¶
Name | 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
this
Inherited from¶
Defined in¶
src/util/evented.ts:74
once¶
▸ once(type
, listener?
): Promise
\<any
> | CanvasSource
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¶
Name | 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¶
Defined in¶
src/util/evented.ts:104
setCoordinates¶
▸ setCoordinates(coordinates
): this
Sets the image's coordinates and re-renders the map.
Parameters¶
Name | 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
this
Inherited from¶
Defined in¶
src/source/image_source.ts:208
setEventedParent¶
▸ setEventedParent(parent?
, data?
): CanvasSource
Bubble all events fired by this instance of Evented to this parent instance of Evented.
Parameters¶
Name | Type |
---|---|
parent? |
Evented |
data? |
any |
Returns¶
this
Inherited from¶
updateImage¶
▸ updateImage(options
): 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¶
Name | Type | Description |
---|---|---|
options |
UpdateImageOptions |
The options object. |
Returns¶
this
this
Inherited from¶
Properties¶
pause¶
• pause: () => void
Disables animation. The map will display a static copy of the canvas image.
Type declaration¶
▸ (): void
Returns¶
void
play¶
• play: () => void
Enables animation. The image will be copied from the canvas to the map on each frame.
Type declaration¶
▸ (): void
Returns¶
void