gpt4 book ai didi

leaflet - Leaflet.draw在draw:edited事件上检索图层类型

转载 作者:行者123 更新时间:2023-12-03 09:45:22 28 4
gpt4 key购买 nike

我正在使用https://github.com/Leaflet/Leaflet.draw插件,并且试图检索已编辑图层的图层类型。

draw:created事件中,我有layerlayerType,但是在draw:edited(保存所有编辑时触发)上,我得到了已编辑图层的列表。

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
}
});
});

关于leaflet - Leaflet.draw在draw:edited事件上检索图层类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18014907/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com