【发布时间】:2016-09-22 16:49:57
【问题描述】:
我以前在这里发布过这个问题,但可能遗漏了一些上下文,所以我要再试一次!我有四个 geojson 层,每个层都是数组格式。要访问这些层中的信息,它似乎是这样嵌套的:layers-object-features-properties。
这是一个数据结构示例:
{
"type": "Feature",
"properties": {
"info_city": "Wuerzburg",
"info_date": 2009,
"info_status": "fac"
},
我要过滤的属性是 date ,在我的数据中,它是字段“info_date”。我编写了以下函数,随机选择一个年份作为测试过滤。这将链接到我地图上的范围滑块栏,范围从 1971 年到 2016 年。
function filterByYear(data){
console.log(data)
f = data.filter(function(d){ return d.features.properties.info_date === '2016';})
console.log(f)
return f;
}
顺便说一句,我也尝试过使用 underscore.js,但无济于事:
f=_.filter(data, function(d) { return d.properties.info_date == 2016; });
所以,我在索引范围滑块的地方调用这个函数,就像这样,使用层 geoJsonLayers.fellows 作为输入。
if (index == 2015) {
filterByYear(geoJsonLayers.fellows)
}
什么都没有发生,并且在 filterByYear 函数中,我能够控制台.log(数据),但没有控制台(f)。我在这里做错了什么?而且,有没有一种更简单的按年份过滤的方法,因为我真正想做的是在用户通过范围滑块移动时进行过滤,即当 index = 1980 时,只会显示“info_date” == 1980 的数据.
【问题讨论】:
标签: javascript jquery leaflet geojson