如何使用 geojson 有选择地启用 onEachFeature 函数
How to selectively enable onEachFeature function with geojson
我有一个可用的 geojson 多边形地图 leaflet.js。当用户单击多边形时,我使用 onEachFeature onclick
进行超链接。
如何为 attribute = 0
的多边形禁用 click 事件 并在 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
我有一个可用的 geojson 多边形地图 leaflet.js。当用户单击多边形时,我使用 onEachFeature onclick
进行超链接。
如何为 attribute = 0
的多边形禁用 click 事件 并在 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