我已经得到了这个非常接近,但我努力了解如何将多个用户提交的表单复选框值传递给Leaflet geoJSON过滤器函数,并只显示这些点。Leaflet:在GeoJSON层中使用动态过滤器
我有什么那么远,
$('#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 –