Using Leaflet with JavaScript I have a map with several GeoJSON Polygon layers.
var assembly = L.geoJSON(null, {onEachFeature: forEachFeature2, style: style2});
$.getJSON(url2, function(data) {
assembly.addData(data);
});
I use the onEachFeature's click event to highlight a polygon yellow when clicked. I currently have the layer name with a setStyle(style2) function before the highlight event to clear/reset the previous polygon's style. So I only get one yellow polygon per click and they don't accumulate. While this works I have several layers so each layer has to have it's own onEachFeature function. I'd like to be able to set this layername by code, and have only one onEachFeature function.
function forEachFeature2(feature, layer) {
layer.on("click", function (e) {
assembly.setStyle(style2); //<<< layername is assembly
layer.setStyle(highlight);
layer.SetStyle(style2) doesn't work.
`