supermap常⽤功能学习
图层组得显隐控制
1. ⽅式⼀
map.addLayer(图层组名称)
map.removeLayer(图层组名称)
图层组在remove得时候并没有彻底得清楚,仍然存在,所以在removeLayer后可以继续add Layer,以达到显隐得控制
2. ⽅式⼆
clearFeatureGroup() {
let that = this
if (that.routeFeatureGroup) {
//that.routeFeatureGroup.clearLayers();
that.routeFeatureGroup.eachLayer(item=>{
item.eachLayer(idx =>{
idx.setOpacity(0)
})
})
}
}
//idx.setOpacity(0) 设置图层的setOpacity()来控制图层的显隐,适合⼤数据量,更改透明度,图层仍然存在
判断地图上是否有图层
map.hasLayer(machineGroup)//machineGroup是图层
创建图标
//⾃定义⼀个icon对象
var customIcon = L.Icon.extend({
options: {
iconSize: [32, 40],
// shadowSize: [50, 64],
iconAnchor: [16, 40],//表⽰图⽚的那个位置对着经纬度点,16对应iconSize⾥的32,40对应的是iconSize⾥的40,从左往右,从上往下
// shadowAnchor: [4, 62],
popupAnchor: [0, -20]
}
});
//new 出项⽬部图标
var macIcon = new customIcon({iconUrl: '../images/machine.png'});
var macIcon_red = new customIcon({iconUrl: '../images/machine-red.png'});