data() {
return {
markericon: []
};
},
mounted(){
this.initmap();//地图实例,不是重点,代码不贴了
},
for(...){
var myIcon = L.divIcon({
html: `<div class="title" >${
item.siteName
}</div><img style="width:30px;height:30px" src="${require("../../assets/radar.png")}"/>`,
className: "my-div-icon",
//动态计算icon的显示宽度
iconSize: that.$L.point(item.siteName.length * 14, 40)
});
let m = that.$L.marker(
coordtransform
.wgs84togcj02(item.longitude, item.latitude)
.reverse(),
{
title: item.siteName,
icon: myIcon
}
);
that.markericon.push(m);
}
that.layerGroup = L.layerGroup(that.markericon);
that.map.addLayer(that.layerGroup);
03-12
576
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-22
4064
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-16
1215
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)