1.百度地图创建在modal层里面:
setTimeout(() => { this.initMap() }) initMap():创建地图的函数=>不加定时器也可以创建,但是创建的一些覆盖物,比如点线面会出现一些偏差,或者创建失败。
initMap(data) {
// 初始化地图
this.modaleditMap = new window.BMap.Map('editmap')
if (this.centerPoint) {
let point = new window.BMap.Point(this.centerPoint.split(',')[0], this.centerPoint.split(',')[1])
this.modaleditMap.centerAndZoom(point, 15)
} else {
let point = new window.BMap.Point(106.002592, 27.033883)
this.modaleditMap.centerAndZoom(point, 15)
}
this.modaleditMap.enableScrollWheelZoom();
window.map = this.modaleditMap;
if (this.saveMapList.length > 0) {
this.saveMapList.map((v, i) => {
let points = []
let listLength = v.split(';');
for (let j = 0; j < listLength.length; j++) {
if (listLength[j] != " ") {
points.push(new BMap.Point(listLength[j].split(',')[0], listLength[j].split(',')[1]))
}
}
points.pop()
var polygon = new BMap.Polygon(points, { fillColor: '#abbcb6', fillOpacity: 0.4, strokeWeight: 1, strokeOpacity: 0.1 }); //创建多边形
this.modaleditMap.addOverlay(polygon); //增加多边形
polygon.enableEditing()
})
}
},