在 D3.js 中,我试图遍历一个 geojson 文件来查找特定属性的值。例如,我想遍历整个 geojson 文件,如果键的值state
等于KS
,则返回该数据。
我对 D3 还很陌生,我还没有找到任何可以让我这样做的东西。我的方法可能存在缺陷,因此非常感谢任何建议。
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"id": "KDDC",
"state": "KS",
"properties": {
"name": "Dodge City Regional Airport",
"address": "100 Airport Road, Dodge City, KS, United States"
},
"geometry": {
"type": "Point",
"coordinates": [
-99.965556000000007,
37.763333000000003
]
}
},
-- 开始代码 --
d3.json("airports.json", function(collection) {
var bounds = d3.geo.bounds(collection),
path = d3.geo.path().projection(project);
path.pointRadius(5);
var locations = g.selectAll("path")
.data(collection.features, function(d) {
if(d.state == "KS"){
console.log(d.state);
return d.state;
}
})
.enter()
.append("path")
.attr("opacity", 100);