CanvasSource
继承至ImageSource
示例
// 添加到地图
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]
]
});
// 更新
var 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');
方法
方法 | 返回值 | 描述 |
---|---|---|
play() | 播放 | |
pause() | 暂停 | |
getCanvas() | 获取 HTML canvas | |
setCoordinates(coordinates) | 设置画布坐标 |
CanvasSourceOptions
向地图中添加CanvasSource时,支持如下属性。
属性 | 类型 | 描述 |
---|---|---|
type | string | 必须为'canvas' |
canvas | string | HTMLCanvasElement | HTMLCanvasElement或其ID |
coordinates | number[][] | [经度,纬度] |
animate | boolean? | 如果一个canvas是静态的,应该指定为false,以增强性能 |