您好,您可以将您的maker先加入到featuregrop中,然后将featuregroup加入map。可以对featuregroup进行遍历
resultLayer = L.featureGroup().addTo(map);
var polyLine = L.polyline([[25, 102], [40, 116]], {color: "red"});
var marker1 = L.marker([25, 102],{
id:1
}), marker2 = L.marker([40, 116],{id:2});
resultLayer.addLayer(polyLine);
resultLayer.addLayer(marker1);
resultLayer.addLayer(marker2);
resultLayer.eachLayer(laer=>{
console.log(laer,'laer')
if(laer.options.id==1){
resultLayer.removeLayer(laer)
}
})