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? 是否带描边:基于line-gap-width实现,默认false
  • borderWeight number? 描边宽度,默认1
  • outlineColor string? 描边颜色,默认#000000
  • strokeColor string? 线条颜色,默认#006600
  • strokeOpacity number? 线条透明度,默认1
  • strokeWeight number? 线条宽度,默认2, 单位像素
  • strokeStyle ("solid" | "dashed")? 线条样式,实现or虚线
  • strokeDasharray Array<number>? 自定义虚线,实线=[0,0,0], 虚线:[10,10], [10, 2, 10],虚线默认:[10, 10]
  • lineJoin ("bevel" | "round" | "miter")? 折线拐点连接处的样式,默认尖角(miter),其他可选:圆角(round),斜角(bevel)
  • lineCap ("round" | "butt" | "square")? 折线两端线帽的样式,默认无头(butt),其他可选:圆头(round),方头(square)
  • userData Record<string, any>? 用户自定义数据对象
  • showDir boolean? 是否显示方向箭头,默认false