var FeatureGroup = new L.FeatureGroup().addTo(map)
const defFeatureGroup ={}
jQuery.extend(true,defFeatureGroup, FeatureGroup)
installPanel(FeatureGroup)
//组装操作面板,显示子图层列表
function installPanel(FeatureGroup) {
var layersList = "";
defFeatureGroup.eachLayer(function(layer){
layersList += '<li><label class="checkbox"><input value="' + layer.options.layersID + '" type="checkbox" class="directory-checkbox" checked /> <span class="name">'+ layer.options.layerName +'</span></label></li>'
});
$("#popupWin").html(layersList)
};
$("#popupWin").on("click", "input", function () {
var checkbox = $(this)
var val = checkbox.val()
defFeatureGroup.eachLayer(function(layer){
if(val === layer.options.layersID){
if (checkbox.is(':checked')) {
FeatureGroup.addLayer(layer);
}
else {
if(FeatureGroup.hasLayer(layer)){
FeatureGroup.removeLayer(layer);
}
}
}
})
})
FeatureGroup.on('layeradd',function(){
console.log("添加成功")
})
在移除图层后勾选添加成功打印添加成功但是所添加的图层没有展示