传单抽奖 : differentiating between multiple controls

标签 leaflet

我正在添加两个 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/

相关文章:

javascript - 如何在 Leaflet openPopup 中设置各种选项?

internet-explorer - Leaflet Label noHide 无指针事件

javascript - 如何使用 React-Leaflet 获取标记集合的边界

javascript - 传单:连接线内可拖动标记的架构

javascript - 如何使svg路径在传单中可点击并通过点击获取路径ID

R 传单图例 : specify order instead of alphabetical

javascript - map 有时一开始无法加载

javascript - React-Leaflet:未捕获类型错误:pointToLayer 不是函数

leaflet - 将 GeoJSON 放在传单 map 上 : Invalid GeoJSON object. 抛出新错误 ('Invalid GeoJSON object.' );

maps - 在 LeafletJS 中使用自定义 map 图像图 block ?