我有一个可用的 geojson 多边形 map ,其中 leaflet.js 。当用户单击多边形时,我使用 onEachFeature onclick
进行超链接。
如何在 attribute = 0
处禁用多边形的点击事件并在 attribute = 1
处启用多边形?
这是我的工作示例 Map
function onclick(e) {
window.open(e.target.feature.properties.link);
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: onclick
});
}
最佳答案
您可以访问 onEachFeature
方法中的实际功能,因此您可以执行如下条件:
function onEachFeature (feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight
});
if (feature.properties.somevalue === 1) {
layer.on('click', onclick);
}
}
Plunker 上的工作示例:http://plnkr.co/edit/vyXqW86Tv7tuLy0GwcPR?p=preview
关于javascript - 如何使用 geojson 有选择地启用 onEachFeature 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35075288/