leaflet ajax geojson,Leaflet:在GeoJSON层中使用动态过滤器

我已经得到了这个非常接近,但我努力了解如何将多个用户提交的表单复选框值传递给Leaflet geoJSON过滤器函数,并只显示这些点。Leaflet:在GeoJSON层中使用动态过滤器

NrRKL.png

我有什么那么远,

$('#map-filters').on("submit", function(e){

e.preventDefault();

map.spin(true,spinOpts);

submittedValues = $(this).serializeArray();

var filteredLocations = L.markerClusterGroup({ chunkedLoading: true }),

filteredLocationsAjax = new L.GeoJSON.AJAX(Routes.filtered_locations_path({format: 'json'}), {

style: style,

pointToLayer: pointToLayer,

onEachFeature: onEachFeature,

filter: function(feature, layer) {

if(submittedValues.length <= 1) {

return feature.properties[submittedValues[0].value];

} else {

How do I return multiple values?

}

}

});

filteredLocationsAjax.on('data:loaded', function() {

map.removeLayer(allLocations);

filteredLocations.addLayer(filteredLocationsAjax);

map.addLayer(filteredLocations);

map.spin(false);

});

});

而且我以GeoJSON的例子...

{

type: "Feature",

geometry: {

type: "Point",

coordinates: [

"-76.286955",

"45.335969"

]

},

properties: {

id: 2,

name: "Mississippi River",

body_of_water: null,

url: "http://0.0.0.0:5000/locations/2",

observations_count: 1,

ph: true,

water_temperature: true,

oxygen: true,

phosphates_threshold: true,

clarity: true,

nitrites: true,

nitrates: true,

issues_count: 3,

water_quality: true,

algae: true

}

}

如果用户只提交了一个能正常工作复选框,地图过滤器正是我想要的。但是,我将如何传递多个值呢?

我见过的人建议使用...

return (feature.properties[value] && feature.properties[value])

但我将如何传递多个值到这样一个return语句,因为用户可以选择1个或20复选框。

2016-08-17

olliekav

+0

跨发布作为http://gis.stackexchange.com/questions/207327/leaflet-use-dynamic-filters-in-geojson-layer –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值