【发布时间】:2020-03-05 23:39:50
【问题描述】:
我在 Leaflet 中有两层。每层都是美国的 geoJSON 地图,有 51 个特征。
我在 mouseout 上附加了一个事件处理程序:
function resetHighlight(e, whichLayer) {
if (whichLayer == terpsLayer) {
console.log('reset');
layerTerps.resetStyle(e.target);
} else if (whichLayer == lawsLayer) {
layerLaws.resetStyle(e.target);
}
}
function onEachFeature(feature, layer) {
layer.on({
mouseout: function(e) {
resetHighlight(e, layer);
}
});
}
这在创建 geoJSON 层时在典型的 onEachFeature 函数中调用。
我不知道如何让 whichLayer 代表 geoJSON 层,而不是单个 51 个特征之一。例如,如果您单击一个要素,您如何让 Leaflet 识别它来自哪个图层组?
【问题讨论】:
标签: javascript leaflet geojson