初始化地图:
initMap() {
let $AMap = window.AMap
if($AMap) {
this.map = new $AMap.Map("map", {
zoom: mapConfig.defaultZoom,
expandZoomRange: true,
zooms: [8, 20],
center: mapConfig.defaultCenter,
pitch: 0,
viewMode: "2D",
mapStyle: "amap://styles/e3408e73e03eeaba546fb05d0b7ea46a"
});
}
},
绘制折线:
addPolyline() {
let $AMap = window.AMap
let path = [
[84.713736, 44.418887],
[84.773736, 44.415887],
]
// 将折线添加至地图实例 当有两个点以上才开始生成折线
this.polyline = new $AMap.Polyline({
path: path.map(a => new $AMap.LngLat(a[0], a[1])), // 设置线覆盖物路径
strokeColor: '#0066FF', // 线颜色
strokeWeight: 3, // 线宽
strokeStyle: "solid", // 线样式
strokeDasharray: [10, 5], // 补充线样式
lineJoin: 'round',
lineCap: 'round',
});
this.polylines.push(this.polyline); // 保存每一个生成的折线
if(this.isDrawLine) {
this.polyline.setMap(this.map); // 添加折线
} else {
this.map.remove(this.polylines); // 清除全部折线
}
},