2.0版本的地图,需要绘制多条折线的时候,就需要循环生成,因此也需要循环清除
for (let j = 0; j < combinedArray.length; j++) {const item = combinedArray[j];this.polyline = new AMap.Polyline({map: this.map,path: item,showDir: true,strokeColor: "#28F", //线颜色// strokeOpacity: 1, //线透明度strokeWeight: 6, //线宽// strokeStyle: "solid" //线样式});this.map.add(this.polyline);}
清除所有的线条
// 删除所线条this.map.getAllOverlays().forEach(function (overlay) {if (overlay instanceof AMap.Polyline) {// 判断是否为Polyline实例overlay.setMap(null); // 从地图上移除}});