leaflet-tag-filter-button icon indicating copy to clipboard operation
leaflet-tag-filter-button copied to clipboard

Dependent (nested?) filters

Open gbiurr opened this issue 4 years ago • 1 comments

Hi. First of all, thank you for this great filter script. Secondly, I must confess I'm sort of a "glue-coder", since despite no initial skills on js I've been playing around and learning from you all to get a final mapping tool which is working pretty well. Temporarily hosted here. My question is related to the use of several filters and the possibility of using nested filtering. My data are arranged in a geojson file, and the tags used in the filter buttons are in a different json file, displaying an array of tags for each filter.

These are my main filters:

 $.getJSON('https://URL_for_tags_File.json', function(data) {
var fam = L.control.tagFilterButton({
  data: data.fam,
  filterOnEveryClick: true,
  icon: '<i class="fas fa-spider" style="font-size:150%;vertical-align: middle;color:red;"> Family</i>',
}).addTo(map);
fam.enableMCG(mcg);
var gen = L.control.tagFilterButton({
  data: data.gen,
  filterOnEveryClick: true,
  icon: '<i class="fas fa-spider" style="font-size:150%;vertical-align: middle;color:#FF8000;"> Genus</i>',
}).addTo(map);
gen.enableMCG(mcg);
var spec = L.control.tagFilterButton({
  data: data.spec,
  filterOnEveryClick: true,
  icon: '<i class="fas fa-spider" style="font-size:150%;vertical-align: middle;color:#04B404;"> Species</i>',
}).addTo(map);
spec.enableMCG(mcg);
});

These are tags used in animal taxonomy. So, let's say that within each "family" there are several "genus", and within each "genus" there are several "species". A tree of species. I wonder whether it would be possible that filtering one family would dinamically modify the list of available genera restricting them to those contained into that chosen family. And the same for species. And I dont know whether that would work "backwards", I mean -instead of first choosing the "parent" family- what would happen if I first choose "child" genus? Would its parent family appear as selected?

I'm sure all this would also mean rebuilding the json tags file, although I'm not sure which way of doing it I may choose. An array of species stating, within an object, which genus and family they belong to? Thank you vey much in advance. Regards. G.

gbiurr avatar Oct 17 '19 13:10 gbiurr