Leaflet map – Zoom and click color on certain states only

I am using leaflet for a map of the usa to show available properties in each state, I would like to remove zoom and clicked color on the states that do not have properties available.

This is my code:

function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());

}
var prevLayerClicked = null;

function onEachFeature(feature, layer) {
layer.on({
//mouseover: highlightFeature,
//mouseout: resetHighlight,
click: function(e){
if (prevLayerClicked !== null) {
// Reset style
prevLayerClicked.setStyle({
weight: 2,
opacity: 1,
color: ‘white’,
dashArray: ”,
fillOpacity: 1.9,
fillColor: getColor(feature.properties.availability)});

}
map.fitBounds(e.target.getBounds());

var layer = e.target;

layer.setStyle({
weight: 1,
color: ‘#fff’,
dashArray: ”,
fillOpacity: 0.9,
fillColor: ‘red’
});

if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}

//info.update(layer.feature.properties.availability);
prevLayerClicked = layer;
}
});
}

I know i will have to change the function onEachFeature, but do not know how to do this. This is my first map project so any help would be great!

Here is the link to my map: https://www.thekeithcorp.com/interactive-map/

Read more here:: Leaflet map – Zoom and click color on certain states only

Leave a Reply

Your email address will not be published. Required fields are marked *