javascript - how to add multiple filters to mapbox leaflet maps -
javascript - how to add multiple filters to mapbox leaflet maps -
i have working mapbox/leaflet map , can filter based on dropdowns 1 of them work, not sure of syntax (or if it's possible) combine filters?
i have real estate map populated json info includes property types , neighborhoods. need combine possible filters, selecting different property type won't erase neighborhood filter.
$('#propertytype').change(function() { if ($(this).val() === 'all') { console.log($(this).val()); markers.setfilter(function(f) { homecoming f.properties['type'] != null; }); } else { console.log($(this).val()); var ptype = $(this).val(); markers.setfilter(function(f) { homecoming f.properties['type'] === ptype; }); homecoming false; } }); $('#neighborhood').change(function() { if ($(this).val() === 'all') { console.log($(this).val()); markers.setfilter(function(f) { homecoming f.properties['neighborhood'] != null; }); } else { console.log($(this).val()); var hood = $(this).val(); markers.setfilter(function(f) { homecoming f.properties['neighborhood'] === hood; }); homecoming false; } });
sure, simplify 1 function:
$('#propertytype, #neighborhood').change(function() { var propertytype = $('#propertytype').val(); var neighborhood = $('#neighborhood').val(); markers.setfilter(function(f) { homecoming (propertytype === 'all' || f.properties.type == propertytype) && (neighborhood === 'all' || f.properties.neighborhood === neighborhood); }); homecoming false; });
(haven't executed code, should work)
javascript map filter leaflet mapbox
Comments
Post a Comment