Skip to content

绘制线

小山 edited this page Oct 9, 2020 · 3 revisions

绘制线

线是由一组经纬度点按照一定的顺序连接而成,在地图上绘制线由 Polyline 类定义实现。通常用来表示一段路、轨迹等线型场景。

添加线

添加折线的同时可以设置线的颜色、宽度等属性,示例代码如下:

await controller.addPolyline(PolylineOption(
  // 经纬度列表
  coordinateList: [
    LatLng(39.984864, 116.305756),
    LatLng(39.983618, 116.305848),
    LatLng(39.982347, 116.305966),
    LatLng(39.982412, 116.308111),
    LatLng(39.984122, 116.308224),
    LatLng(39.984955, 116.308099),
  ],
  // 折线宽度
  width: 10,
  // 折线颜色
  strokeColor: Colors.green,
));

移除折线

从地图移除折线

final polyline = await controller.addPolyline(PolylineOption(
  // 经纬度列表
  coordinateList: [
    LatLng(39.984864, 116.305756),
    LatLng(39.983618, 116.305848),
    LatLng(39.982347, 116.305966),
    LatLng(39.982412, 116.308111),
    LatLng(39.984122, 116.308224),
    LatLng(39.984955, 116.308099),
  ],
));
await polyline.remove();

腾讯地图

开发指南

Clone this wiki locally