1 init() { //地圖-固定顯示重慶市 2 let _this = this 3 _this.map = new AMap.Map("container", { 4 resizeEnable: true, 5 center: [107.983524, 30.026571], 6 zoom: 7, 7 mapStyle: "amap://styles/a2425e25c6fe2c4e890047477c3445ec", 8 }) 9 new AMap.DistrictSearch({ 10 extensions: 'all', 11 subdistrict: 0 12 }).search('重慶市', function(status, result) { 13 let outer = [ 14 new AMap.LngLat(-360, 90, true), 15 new AMap.LngLat(-360, -90, true), 16 new AMap.LngLat(360, -90, true), 17 new AMap.LngLat(360, 90, true), 18 ]; 19 let holes = result.districtList[0].boundaries 20 let pathArray = [ 21 outer 22 ]; 23 pathArray.push.apply(pathArray, holes) 24 _this.polygon = new AMap.Polygon({ 25 pathL: pathArray, 26 strokeColor: 'rgb(20,164,173)', 27 strokeWeight: 4, 28 strokeOpacity: 0.5, 29 fillColor: '#081b39', 30 fillOpacity: 1, 31 strokeStyle: 'dashed', 32 strokeDasharray: [10, 2, 10] 33 }); 34 _this.polygon.setPath(pathArray); 35 _this.map.add(_this.polygon); 36 }) 37 },
在method中寫入該段代碼,需先在data中定義map為null,polygon為一個空數組,然后將本段代碼放在mounted中調用
參考地址:https://blog.csdn.net/liujucai/article/details/100070540