高德地图 初始化时 设置中心点和级别无效,于是延迟1秒后重新设置。
that.map.setZoomAndCenter(13, [108.095907, 23.919379])
initMap() {
//仅供参考
var that = this;
let backPicUrl = '';
backPicUrl = (mapbg);
that.map = new AMap.Map('gd_map_d', {
zoom: 13,
mapStyle: 'amap://styles/darkblue',
center: [108.095907, 23.919379]
// map的样式需要到高德后台去自定义
});
setTimeout(() => {
that.map.setZoomAndCenter(13, [108.095907, 23.919379])
}, 1000)
this.potList.forEach(item => {
// 根据type判断icon类型
// 1 隧道 2服务区 3收费站 4 管理中心 5 互通
var staticLine = [];
item.spotList.forEach((type) => {
var marker = new AMap.Marker({
position: [type.longitude, type.latitude],
map: that.map,
extData: type,
extData2: item,
icon: new AMap.Icon({
image: that.filterData(type.spotType),
imageSize: new AMap.Size(68, 93),
size: new AMap.Size(68, 93)
})
});
staticLine.push([type.longitude, type.latitude])
that.map.add(marker);
marker.on('click', that.markerClick)
});
// 绘制线路
var polyline = new AMap.Polyline({
map: that.map,
path: staticLine,
strokeColor: "#62D97A", //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 5, //线宽
strokeStyle: "solid" //线样式
});
})
that.map.setFitView();
// map.on("click", () => {
// infoWindow && infoWindow.close();
// });
},