I'm using Leaflet filter on geoJson data. I'm able to apply it with a simple criteria :
filter: function(feature, layer) {
return feature.properties.field1 == "yes";
}
I can also apply two criteria with logical operators like &&
or ||
:
filter: function(feature, layer) {
return (feature.properties.field1 == "yes" && feature.properties.field2 == "yes");
}
I want now to insert a condition (depending of a variable):
filter: function(feature, layer) {
if (varState == "01") {
return (feature.properties.field1 == "yes" && feature.properties.field2 == "yes");
}
else if (varState == "02") {
return (feature.properties.field1 == "yes" && feature.properties.field2 == "no");
}
else {
return feature.properties.field1 == "yes";
}
}
Does someone has already succeed this ?
feature.properties.field1 == "yes" && feature.properties.field2 == "yes";
"yes"
for bothfield
andfield2
?"yes"
for bothfield1
andfield2
if
else if
else
not recognize by filters.