Skip to content

Polyline ​

Polyline ​

构造折线对象,通过PolylineOptions指定折线样式

继承OverlayBase

Examples ​

javascript
const polyline = new DiMap.Polyline({
 map: map,
 path: [
  [116.397411, 39.909186],
  [116.410886, 39.909186],
  [116.410886, 39.924397],
  [116.397411, 39.924397]
 ],
 strokeColor: "#FF33FF",
 strokeOpacity: 0.2,
 strokeWeight: 10,
 strokeStyle: "dashed",
 lineJoin: "round",
 lineCap: "round",
 showDir: true,
 userData: {
  id: "polyline1"
 }
})
polyline.show()

constructor ​

Parameters ​

setPath ​

设置path

Parameters ​

Returns this

getPath ​

获取path

Returns Array<LngLatLike>

getLength ​

获取折线物理长度

Returns number 单位:米

getBounds ​

获取折线的矩形范围对象

Examples ​

javascript
const bounds = polyline.getBounds()
map.fitBounds(bounds, {
 padding: 100
})

Returns LngLatBounds

PolylineOptions ​

折线属性

Properties ​

参数名必选类型描述
map是Map地图实例
path是Array<LngLatLike>折线路径
isOutline否boolean是否带描边,默认false
borderWeight否number描边宽度,默认1
outlineColor否string描边颜色,默认#000000
strokeColor否string线条颜色,默认#006600
strokeOpacity否number线条透明度,默认1
strokeWeight否number线条宽度,默认2,单位像素
strokeStyle否"solid" | "dashed"线条样式,实线或虚线
strokeDasharray否Array<number>自定义虚线样式。实线:[0,0,0];虚线:[10,10](默认);点画线:[10,2,10]
lineJoin否"bevel" | "round" | "miter"折线拐点连接处的样式,默认尖角(miter),可选:圆角(round),斜角(bevel)
lineCap否"round" | "butt" | "square"折线两端线帽的样式,默认butt,可选:圆头(round),方头(square)
userData否Record<string, any>用户自定义数据对象
showDir否boolean是否显示方向箭头,默认false