gpt4 book ai didi

javascript - 如何向 Mapbox 传单 map 添加多个过滤器

转载 作者:行者123 更新时间:2023-12-03 11:33:28 24 4
gpt4 key购买 nike

我有一个可用的 map 框/传单 map ,我可以根据下拉列表进行过滤,但只有其中一个可以工作,不确定组合过滤器的语法(或者是否可能)?

我基本上有一个用 json 数据填充的房地产 map ,其中包括特性类型和社区。需要组合可能的过滤器,因此选择不同的属性类型不会删除邻域过滤器。

$('#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 - 如何向 Mapbox 传单 map 添加多个过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26637998/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com