我正在使用 https://github.com/Leaflet/Leaflet.draw插件,我试图找出如何检索编辑图层的图层类型。 在绘制:创建的事件,我有层和layerType,但在绘制:编辑(触发时保存所有编辑)我得到一个列
          在绘制:创建的事件,我有层和layerType,但在绘制:编辑(触发时保存所有编辑)我得到一个列表的编辑的层。
draw:created事件
map.on('draw:created', function (e) {
    var type = e.layerType,
        layer = e.layer;
    if (type === 'marker') {
        // Do marker specific actions
    }
    // Do whatever else you need to. (save to db, add to map etc)
    map.addLayer(layer);
}); 
 draw:edited事件
map.on('draw:edited', function (e) {
    var layers = e.layers;
    layers.eachLayer(function (layer) {
        //do stuff, but I can't check which type I'm working with
        // the layer parameter doesn't mention its type
    });
}); 
 感谢您的时间。
你可以使用instanceof (docs here)。map.on('draw:edited', function (e) {
    var layers = e.layers;
    layers.eachLayer(function (layer) {
        if (layer instanceof L.Marker){
            //Do marker specific actions here
        }
    });
});
        
             