GeoJSONSource
A source containing GeoJSON.
(See the Style Specification for detailed documentation of options.)
Constructor
Name | |
---|---|
GeoJSONSource | new GeoJSONSource(id: string, options: GeoJSONSourceOptions, dispatcher: Dispatcher, eventedParent: Evented) Parameters
|
Methods
Method | |
---|---|
abortTile | abortTile(tile: Tile) Parameters
Return Value: void |
fire | fire(event: string | Event, properties: any) Parameters
Return Value: GeoJSONSource |
getClusterChildren | getClusterChildren(clusterId: number, callback: Callback) Parameters
Return Value: GeoJSONSource For clustered sources, fetches the children of the given cluster on the next zoom level (as an array of GeoJSON features). |
getClusterExpansionZoom | getClusterExpansionZoom(clusterId: number, callback: Callback) Parameters
Return Value: GeoJSONSource For clustered sources, fetches the zoom at which the given cluster expands. |
getClusterLeaves | getClusterLeaves(clusterId: number, limit: number, offset: number, callback: Callback) Parameters
Return Value: GeoJSONSource For clustered sources, fetches the original points that belong to the cluster (as an array of GeoJSON features). |
hasTransition | hasTransition() Return Value: boolean |
listens | listens(type: string) Parameters
Return Value: any Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type. |
load | load() Return Value: void |
loadTile | loadTile(tile: Tile, callback: Callback) Parameters
Return Value: void |
loaded | loaded() Return Value: boolean |
off | off(type: string, listener: Listener) Parameters
Return Value: GeoJSONSource Removes a previously registered event listener. |
on | on(type: string, listener: Listener) Parameters
Return Value: GeoJSONSource Adds a listener to a specified event type. |
onAdd | onAdd(map: Map) Parameters
Return Value: void |
onRemove | onRemove() Return Value: void |
once | once(type: string, listener: Listener) Parameters
Return Value: GeoJSONSource 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. |
serialize | serialize() Return Value: any |
setData | setData(data: string | GeoJSON) Parameters
Return Value: GeoJSONSource Sets the GeoJSON data and re-renders the map. |
setEventedParent | setEventedParent(parent: Evented, data: any) Parameters
Return Value: GeoJSONSource Bubble all events fired by this instance of Evented to this parent instance of Evented. |
unloadTile | unloadTile(tile: Tile) Parameters
Return Value: void |
Example
1map.addSource('some id', {
2 type: 'geojson',
3 data: 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_ports.geojson'
4});
ImageSource
A data source containing an image.
(See the Style Specification for detailed documentation of options.)
Constructor
Name | |
---|---|
ImageSource | new ImageSource(id: string, options: CanvasSourceSpecification | ImageSourceSpecification | VideoSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) Parameters
|
Methods
Method | |
---|---|
fire | fire(event: string | Event, properties: any) Parameters
Return Value: ImageSource |
hasTransition | hasTransition() Return Value: boolean |
listens | listens(type: string) Parameters
Return Value: any Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type. |
load | load(newCoordinates: Coordinates, successCallback: Function) Parameters
Return Value: void |
loadTile | loadTile(tile: Tile, callback: Callback) Parameters
Return Value: void |
loaded | loaded() Return Value: boolean |
off | off(type: string, listener: Listener) Parameters
Return Value: ImageSource Removes a previously registered event listener. |
on | on(type: string, listener: Listener) Parameters
Return Value: ImageSource Adds a listener to a specified event type. |
onAdd | onAdd(map: Map) Parameters
Return Value: void |
once | once(type: string, listener: Listener) Parameters
Return Value: ImageSource 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. |
prepare | prepare() Return Value: void |
serialize | serialize() Return Value: any |
setCoordinates | setCoordinates(coordinates: Coordinates) Parameters
Return Value: ImageSource Sets the image's coordinates and re-renders the map. |
setEventedParent | setEventedParent(parent: Evented, data: any) Parameters
Return Value: ImageSource Bubble all events fired by this instance of Evented to this parent instance of Evented. |
updateImage | updateImage(options: { coordinates: Coordinates,url: string }) Parameters
Return Value: ImageSource 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. |
Example
1// add to map
2map.addSource('some id', {
3 type: 'image',
4 url: 'https://nextbillion.ai/images/foo.png',
5 coordinates: [
6 [-76.54, 39.18],
7 [-76.52, 39.18],
8 [-76.52, 39.17],
9 [-76.54, 39.17]
10 ]
11});
12
13// update coordinates
14var mySource = map.getSource('some id');
15mySource.setCoordinates([
16 [-76.54335737228394, 39.18579907229748],
17 [-76.52803659439087, 39.1838364847587],
18 [-76.5295386314392, 39.17683392507606],
19 [-76.54520273208618, 39.17876344106642]
20]);
21
22// update url and coordinates simultaneously
23mySource.updateImage({
24 url: 'https://nextbillion.ai/images/bar.png',
25 coordinates: [
26 [-76.54335737228394, 39.18579907229748],
27 [-76.52803659439087, 39.1838364847587],
28 [-76.5295386314392, 39.17683392507606],
29 [-76.54520273208618, 39.17876344106642]
30 ]
31})
32
33map.removeSource('some id'); // remove
VideoSource
A data source containing video.
(See the Style Specification for detailed documentation of options.)
Constructor
Name | |
---|---|
VideoSource | new VideoSource(id: string, options: VideoSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) Parameters
|
Methods
Method | |
---|---|
fire | fire(event: string | Event, properties: any) Parameters
Return Value: VideoSource |
getVideo | getVideo() Return Value: HTMLVideoElement Returns the HTML video element. |
hasTransition | hasTransition() Return Value: boolean |
listens | listens(type: string) Parameters
Return Value: any Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type. |
load | load() Return Value: void |
loadTile | loadTile(tile: Tile, callback: Callback) Parameters
Return Value: void |
loaded | loaded() Return Value: boolean |
off | off(type: string, listener: Listener) Parameters
Return Value: VideoSource Removes a previously registered event listener. |
on | on(type: string, listener: Listener) Parameters
Return Value: VideoSource Adds a listener to a specified event type. |
onAdd | onAdd(map: Map) Parameters
Return Value: void |
once | once(type: string, listener: Listener) Parameters
Return Value: 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. |
pause | pause() Return Value: void Pauses the video. |
play | play() Return Value: void Plays the video. |
prepare | prepare() Return Value: void Sets the video's coordinates and re-renders the map. |
seek | seek(seconds: number) Parameters
Return Value: void Sets playback to a timestamp, in seconds. |
serialize | serialize() Return Value: none |
setCoordinates | setCoordinates(coordinates: Coordinates) Parameters
Return Value: VideoSource Sets the image's coordinates and re-renders the map. |
setEventedParent | setEventedParent(parent: Evented, data: any) Parameters
Return Value: VideoSource Bubble all events fired by this instance of Evented to this parent instance of Evented. |
updateImage | updateImage(options: { coordinates: Coordinates,url: string }) Parameters
Return Value: VideoSource 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. |
Example
1// add to map
2map.addSource('some id', {
3 type: 'video',
4 url: [
5 'https://nextbillion.ai/blog/assets/baltimore-smoke.mp4',
6 'https://nextbillion.ai/blog/assets/baltimore-smoke.webm'
7 ],
8 coordinates: [
9 [-76.54, 39.18],
10 [-76.52, 39.18],
11 [-76.52, 39.17],
12 [-76.54, 39.17]
13 ]
14});
15
16// update
17var mySource = map.getSource('some id');
18mySource.setCoordinates([
19 [-76.54335737228394, 39.18579907229748],
20 [-76.52803659439087, 39.1838364847587],
21 [-76.5295386314392, 39.17683392507606],
22 [-76.54520273208618, 39.17876344106642]
23]);
24
25map.removeSource('some id'); // remove
CanvasSource
A data source containing the contents of an HTML canvas. See CanvasSourceOptions for detailed documentation of options.
Constructor
Name | |
---|---|
CanvasSource | new CanvasSource(id: string, options: CanvasSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) Parameters
|
Methods
Method | |
---|---|
fire | fire(event: string | Event, properties: any) Parameters
Return Value: CanvasSource |
getCanvas | getCanvas() Return Value: HTMLCanvasElement Returns the HTML canvas element. |
hasTransition | hasTransition() Return Value: boolean |
listens | listens(type: string) Parameters
Return Value: any Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type. |
load | load() Return Value: void Disables animation. The map will display a static copy of the canvas image. |
loadTile | loadTile(tile: Tile, callback: Callback) Parameters
Return Value: void |
loaded | loaded() Return Value: boolean |
off | off(type: string, listener: Listener) Parameters
Return Value: CanvasSource Removes a previously registered event listener. |
on | on(type: string, listener: Listener) Parameters
Return Value: CanvasSource Adds a listener to a specified event type. |
onAdd | onAdd(map: Map) Parameters
Return Value: void |
onRemove | onRemove() Return Value: void |
once | once(type: string, listener: Listener) Parameters
Return Value: 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. |
prepare | prepare() Return Value: void |
serialize | serialize() Return Value: any |
setCoordinates | setCoordinates(coordinates: Coordinates) Parameters
Return Value: CanvasSource Sets the image's coordinates and re-renders the map. |
setEventedParent | setEventedParent(parent: Evented, data: any) Parameters
Return Value: CanvasSource Bubble all events fired by this instance of Evented to this parent instance of Evented. |
updateImage | updateImage(options: { coordinates: Coordinates,url: string }) Parameters
Return Value: CanvasSource 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. |
Example
1// add to map
2map.addSource('some id', {
3 type: 'canvas',
4 canvas: 'idOfMyHTMLCanvas',
5 animate: true,
6 coordinates: [
7 [-76.54, 39.18],
8 [-76.52, 39.18],
9 [-76.52, 39.17],
10 [-76.54, 39.17]
11 ]
12});
13
14// update
15var mySource = map.getSource('some id');
16mySource.setCoordinates([
17 [-76.54335737228394, 39.18579907229748],
18 [-76.52803659439087, 39.1838364847587],
19 [-76.5295386314392, 39.17683392507606],
20 [-76.54520273208618, 39.17876344106642]
21]);
22
23map.removeSource('some id'); // remove