Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependent (nested?) filters #33

Open
gbiurr opened this issue Oct 17, 2019 · 1 comment
Open

Dependent (nested?) filters #33

gbiurr opened this issue Oct 17, 2019 · 1 comment
Labels

Comments

@gbiurr
Copy link

gbiurr commented Oct 17, 2019

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.

@maydemirx
Copy link
Owner

maydemirx commented Oct 18, 2019

Hello i'm sorry. There is no feature about tag filtering between tagFilterButton instances. But i try to explain some trics of what i understand your issue.

For tag data filter

  • You can rebuild your child tagFilterButton instance at the "onSelectionComplete" callback of parent tagFilterButton. in this case you should organize your array of tags data. For example when the user click any tag on the "fam" you can rebuild "gen" at the onSelectionComplete callback of "fam". After "gen" initialization you can use addToRelated function of "gen" and pass the "fam" instance to it.

  • In this way your "fam" and "gem" works like "country" > "state" selectboxes. for addToRelated please check the "Releated Buttons Usage" of demo page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants