let img = new Image();
img.src = require('@/assets/icon/car.png');
this.iconLayer = new mapvgl.IconLayer({
width: 25,
height: 25,
icon:img,
enablePicked: true, // 是否可以拾取
selectedIndex: -1, // 选中项
selectedColor: 'rgb(230,104,38)', // 选中项颜色
autoSelect: true, // 根据鼠标位置来自动设置选中项
onClick: (e) => { // 点击事件
if(e.dataIndex!=-1){}
},
});
import redCar from "@/assets/icon/redCar.png"
import greenCar from "@/assets/icon/greenCar.png"
vue3中图标引入方法区别于vue2,是一种全新的方式
const redCar = new URL('../../../assets/icon/redCar.png', import.meta.url).href //引用图标
let icon = new BMapGL.Icon(redCar, new BMapGL.Size(10, 10))
<li v-for="(item, index) in list" :key="index"><img :src="exportImgSrc(item.icons)" /></li>
const exportImgSrc = (src: string): string => {
if (src) {
return new URL(`../assets/icon/${src}`, import.meta.url).href;
} else {
return new URL(`../assets/icon/default.png`, import.meta.url).href;
}
};