如何将多个过滤器添加到mapbox小册子地图
问题描述:
我有一个工作mapbox /传单地图,我可以根据下拉列表进行过滤,但只有其中一个可以工作,不确定语法(或者如果可能)组合过滤器?如何将多个过滤器添加到mapbox小册子地图
我基本上有一个填充json数据的房地产地图,其中包括房产类型和街区。需要组合可能的过滤器,因此选择不同的属性类型不会擦除邻域过滤器。
$('#propertytype').change(function() {
if ($(this).val() === 'all') {
console.log($(this).val());
markers.setFilter(function(f) {
return f.properties['type'] != null;
});
} else {
console.log($(this).val());
var ptype = $(this).val();
markers.setFilter(function(f) {
return f.properties['type'] === ptype;
});
return false;
}
});
$('#neighborhood').change(function() {
if ($(this).val() === 'all') {
console.log($(this).val());
markers.setFilter(function(f) {
return f.properties['neighborhood'] != null;
});
} else {
console.log($(this).val());
var hood = $(this).val();
markers.setFilter(function(f) {
return f.properties['neighborhood'] === hood;
});
return false;
}
});
答
当然,简化成一个功能:
$('#propertytype, #neighborhood').change(function() {
var propertyType = $('#propertytype').val();
var neighborhood = $('#neighborhood').val();
markers.setFilter(function(f) {
return (propertyType === 'all' || f.properties.type == propertyType) &&
(neighborhood === 'all' || f.properties.neighborhood === neighborhood);
});
return false;
});
(尚未执行该代码,但应工作)
完美!这是我想要做的,但不知道它是如何在JavaScript中完成的。谢谢! – nrutas 2014-10-30 20:12:11