I'm new about leaflet a I try to select/deselect layer using a mouse click. Firstly mi map is in this way
After click on a layer i want to select it and highlight
Now if i again click on previos select layer i want to deselect it and reset the highlight. This is the code that i use to do this.
onEachFeature: function(feature,layer) {
layer.setStyle({fillOpacity: 0.0 , color: '#424a44', weight: 2});
layer.on('click', function(e) {
let isLayerAlreadySelected = // Some logic to undestand if layer alreeady selected
if(isLayerAlreadySelected)
layer.setStyle({fillOpacity: 0.0 , color: '#424a44', weight: 2});
else
layer.setStyle({fillOpacity: 0.4 , color: '#004691', weight: 3});
}
}
but sometimes when i try to deselect a layer previously selected the layer style in not resel the opacity remain. Some suggestion about this?
from How to clear leaflet layer after click
No comments:
Post a Comment