javascript - jQuery/Mapbox multiple data filters issue -
i have map, built in mapbox, feeds off of geojson. i'm trying filter markers 2 criteria: category (multiple true/false properties) , year. want 2 filters work @ same time, not cancel each other out, i'm getting stuck when combining them.
each filter works independently — have year:
$('.year a').on("click", function() { var year = $(this).data('filter'); $(this).addclass('active').siblings().removeclass('active'); featurelayer.setfilter(function(f) { return (year === 'all' || f.properties.year === year); }); return false; });
and have category:
$('.category a').on("click", function() { var category = $(this).data('filter'); $(this).addclass('active').siblings().removeclass('active'); featurelayer.setfilter(function(f) { return ((category === 'all') ? true : f.properties[category] === true); }); return false; });
this how combined them, know i'm doing wrong.
$('.category a, .year a').on("click", function() { var category = $(this).data('filter'); var year = $(this).data('filter'); $(this).addclass('active').siblings().removeclass('active'); featurelayer.setfilter(function(f) { return ((category === 'all') ? true : f.properties[category] === true) && (year === 'all' || f.properties.year === year); }); return false; });
i think i'm missing step differentiate 2 filter searches, i'm not familiar jquery, i'm not sure need do. specifically, think i'm missing part category var gets associated .category a, , year var gets associated .year a.
any pointers in right direction appreciated. thanks!
suoz,
your problem might way targeting selectors bind click event. right way is:
$('.category a, .year a').on('click', function() { ... });
you don't said issue, think might problem or 1 of them.
Comments
Post a Comment