Skip to content

线 ​

​ 根据线数据,绘制相应的线段

示例 ​

一. 添加数据源

javascript
// 添加数据源第一个参数为数据源id,这里使用标准的GeoJSON格式
map.addSource('route', {
    'type': 'geojson',
    'data': {
        'type': 'Feature',
        'properties': {},
        'geometry': {
            'type': 'LineString',
            'coordinates': [
                [113.993571,22.590078],
                [113.963702,22.581271],
                [113.967478,22.550201],
                [114.005072,22.541957],
                [114.01829,22.5573305],
                [114.027045,22.582856]
            ]
        }
    }
});

二. 添加图层

javascript
map.addLayer({
    'id': 'route',// 图层id
    'type': 'line',// 渲染方式
    'source': 'route',// 绑定数据源id
    'layout': {
        'line-join': 'round',// 线连接处样式
        'line-cap': 'round',// 线端点样式
    },
    'paint': {
        'line-color': '#0000ff',// 颜色
        'line-width': 8, // 线宽(单位像素)
    }
});

V3.2-202604301400