gpt4 book ai didi

传单抽奖 : differentiating between multiple controls

转载 作者:行者123 更新时间:2023-12-01 04:52:19 28 4
gpt4 key购买 nike

我正在添加两个 Leaflet Draw 实例( https://github.com/Leaflet/Leaflet.draw ),如下所示(仅使用线条):

var drawControl = new L.Control.Draw({
draw: {
polygon: false,
rectangle: false,
circle: false,
marker: false
}
});
map.addControl(drawControl);

var drawControl2 = new L.Control.Draw({
draw: {
polygon: false,
rectangle: false,
circle: false,
marker: false
}
});
map.addControl(drawControl2);

现在我想听 draw:drawvertex事件并根据我是否激活了 drawControl 做不同的事情或 drawControl2 :
map.on('draw:drawvertex', function (e) {
console.log("Vertex drawn", e);
});

如何区分当前处于事件状态的 drawControl?

最佳答案

这是一种知道哪个 drawControl 处于事件状态的肮脏方法。

诀窍是将它们放在不同的 map 角落。它有助于检查哪个 ul.leaflet-draw-actions当用户绘制时可见。 div.leaflet-top中的那个或 div.leaflet-bottom 中的那个例如 :

var drawControl = new L.Control.Draw({
position: 'topleft',
draw: {
polygon: false,
rectangle: false,
circle: false,
marker: false
}
});
map.addControl(drawControl);

var drawControl2 = new L.Control.Draw({
position: 'bottomleft',
draw: {
polygon: false,
rectangle: false,
circle: false,
marker: false
}
});
map.addControl(drawControl2);

map.on('draw:drawvertex', function (e) {
console.log("Vertex drawn", e);
if ($('div.leaflet-top ul.leaflet-draw-actions').is(':visible')){
console.log('it was drawn with drawControl');
}
else {
console.log('it was drawn with drawControl2 !');
}
});

它很脏,但它有效。

关于传单抽奖 : differentiating between multiple controls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40044514/

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