I have a GeoJSON point layer group styled as a circle marker; it has a color attribute which can be one of many values: white, black, blue, red etc.
I want to create a filter based on that attribute, so I created a Bootstrap button with a Dropdown for a selection of four attributes.
I tried the built-in filter as pointed in this question,
var redcolor = L.geoJson(colors, {filter: redFilter})
function redFilter(feature) {
if (feature.properties.hue === "red") return true
}
and assigning it to its respective button using jQuery:
$("#red").click(function(event) {
event.preventDefault();
if(map.hasLayer(redcolor)) {
$(this).removeClass('selected');
map.removeLayer(redcolor);
} else {
map.addLayer(redcolor);
$(this).addClass('selected');
}
})
but I don't want to create a separate layer group; the filtering should happen in the original one.