注:初始化天地图请看上一篇文章
(1)在地图上添加线并编辑
let line: any
//相关配置
let config = {
showLabel: false,//测距功能展示
color: 'blue',
weight: 5,
opacity: 0.5,
fillColor: '#FFFFFF',
fillOpacity: 0.5,
}
//地图添加多条线
channelData.value.forEach((item: any) => {
//item.sectionList为点位数组
line = new (window as any).T.Polyline(item.sectionList, config)
map.addOverLay(line)
//开启编辑线功能
line.enableEdit()
})
(2)在地图上画线
//画线样式配置
let config = {
showLabel: false,
color: 'blue',
weight: 3,
opacity: 0.5,
fillColor: '#FFFFFF',
fillOpacity: 0.5,
}
//创建画线对象
let handler = new (window as any).T.PolylineTool(map, config)
//启用画线
handler.open()
//关闭画线
//handler.close()
//双击画线完成监听事件
handler.addEventListener('draw', (e: any) => {
let arry = e.currentLnglats
//打印画线坐标点数组
console.log(arry)
})