Polyline

使用浏览器的矢量制图工具在地图上绘制折线的覆盖物。

构造函数

  • 创建折线覆盖物对象

    参数类型说明
    pointsPoint折线的坐标点数组
    opts 可选PolylineOptions可选参数
    属性类型说明
    clipboolean是否进行跨经度180度裁剪,绘制跨经度180度的折线时可设置为 false 以优化效果
    enableClickingboolean是否响应点击事件
    enableEditingboolean是否启用线编辑
    enableMassClearboolean是否在调用 map.clearOverlays() 时清除此覆盖物
    geodesicboolean是否开启大地线模式,为 true 时两点连线将以大地线的形式呈现
    linkRightboolean跨180度经线时走右侧
    strokeColorstring折线颜色,格式为 '#xxxxxx'
    strokeLineCapstring描边线端头类型,可选 'round'、'butt'、'square'
    strokeOpacitynumber折线的透明度,取值范围0 - 1
    strokeStylestring折线的样式,支持 'solid'、'dashed'、'dotted'
    strokeWeightnumber折线的宽度,以像素为单位

    返回值 Polyline

    示例代码1

    const polyline = new BMap.Polyline([
    new BMap.Point(116.399, 39.910),
    new BMap.Point(116.405, 39.920),
    new BMap.Point(116.415, 39.915),
    ]);
    map.addOverlay(polyline);

    示例代码2:自定义样式

    const polyline = new BMap.Polyline(
    [new BMap.Point(116.399, 39.910), new BMap.Point(116.415, 39.915)],
    { strokeColor: '#0055ff', strokeWeight: 4, strokeOpacity: 0.8 }
    );
    map.addOverlay(polyline);

方法

  • 添加事件监听函数

    参数类型说明
    eventstring事件名称
    handlerFunction事件处理函数

    返回值 void

    示例代码1

    polyline.addEventListener('click', (e) => {
    console.log('polyline clicked', e);
    });
  • 关闭折线编辑功能

    返回值 void

  • 禁止覆盖物在 map.clearOverlays() 方法中被清除

    返回值 void

  • 开启折线编辑功能

    返回值 void

  • 允许覆盖物在 map.clearOverlays() 方法中被清除

    返回值 void

  • 返回折线的地理区域范围

    返回值 Bounds

  • 返回覆盖物所在的地图实例

    返回值 Map

  • 返回折线的坐标点数组

    返回值 Point[]

  • 返回折线颜色

    返回值 string

  • 返回折线透明度

    返回值 number

  • 返回折线样式

    返回值 string

  • 返回折线线宽

    返回值 number

  • 移除事件监听函数

    参数类型说明
    eventstring事件名称
    handlerFunction事件处理函数

    返回值 void

    示例代码1

    const handler = (e: any) => { console.log(e); };
    polyline.addEventListener('click', handler);
    polyline.removeEventListener('click', handler);
  • 设置折线的坐标点数组

    参数类型说明
    pathPoint坐标点数组

    返回值 void

    示例代码1

    polyline.setPath([
    new BMap.Point(116.399, 39.910),
    new BMap.Point(116.405, 39.920),
    new BMap.Point(116.415, 39.915),
    ]);
  • 修改指定索引处的坐标点,索引从0开始

    参数类型说明
    indexnumber坐标点索引
    pointPoint新的坐标点

    返回值 void

    示例代码1

    polyline.setPositionAt(0, new BMap.Point(116.400, 39.912));
    
  • 设置折线颜色

    参数类型说明
    colorstring颜色值,格式为 '#xxxxxx'

    返回值 void

    示例代码1

    polyline.setStrokeColor('#ff0000');
    
  • 设置折线透明度

    参数类型说明
    opacitynumber透明度,取值范围0 - 1

    返回值 void

    示例代码1

    polyline.setStrokeOpacity(0.6);
    
  • 设置折线样式

    参数类型说明
    stylestring线样式,'solid' 实线或 'dashed' 虚线

    返回值 void

    示例代码1

    polyline.setStrokeStyle('dashed');
    
  • 设置折线线宽

    参数类型说明
    weightnumber线宽,单位像素,须为大于等于1的整数

    返回值 void

    示例代码1

    polyline.setStrokeWeight(4);
    
  • 设置覆盖物的 zIndex

    参数类型说明
    zIndexnumber层叠顺序值

    返回值 void

    示例代码1

    polyline.setZIndex(10);