{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "id": 1, "prop1": "val1", "prop2": "val2", "prop3": "val3" }, "geometry": { "type": "Polygon", "coordinates": [
[
[168.77944820788511, 672.173755174731468],
[278.300419534049979, 672.173755174731468],
[278.300419534049979, 590.815319332437525],
[168.77944820788511, 590.815319332437525],
[168.77944820788511, 672.173755174731468]
]
] } },
{ "type": "Feature", "properties": { "id": 2, "prop1": "val1", "prop2": "val2", "prop3": "val3" }, "geometry": { "type": "Polygon", "coordinates": [
[
[282.211882795699466, 672.369328337813613],
[334.625490501792683, 672.369328337813613],
[334.625490501792683, 591.01089249551967],
[282.211882795699466, 591.01089249551967],
[282.211882795699466, 672.369328337813613]
]
] } }
]
}
上述提取其屬性是包含有關如何在頁面上畫一些路徑geometry
數據的GeoJSON的文件的摘錄。每個通道還具有路徑的properties
描述特性(例如prop1
,prop2
和prop3
。D3 V4:確定從以GeoJSON根據點擊事件
在我的網頁上還有一個鏈接列表,每一個都具有對應於GeoJSON內容之一的id
屬性。文件
<ul>
<li id="prop1"><a href="#">Link1</a></li>
<li id="prop2"><a href="#">Link2</a></li>
<li id="prop3"><a href="#">Link3</a></li>
</ul>
我想什麼我的代碼做:
- 當鏈接用戶點擊提取其
id
[1] - 使用該
id
以提取相應屬性的值以GeoJSON [2] - 使用該值的屬性
status
分配給路徑,我將在以後使用樣式的路徑[3]
我被困在第二點,因爲我不能根據提取的id
來定義應提取哪個屬性)。
//OPTION 1
d3.select('#myList').selectAll('li').on('click', function() {
propPicked = this.id
propPicked = 'd.properties.' + propPicked //[1]
d3.selectAll('path').each(function (d) {
d3.select(this).attr('status'. function (d) { //[3]
return propPicked //[2] this is where I am stuck
})
})
//OPTION 2
d3.select('#myList').selectAll('li').on('click', function() {
propPicked = this.id //[1]
d3.selectAll('path').each(function (d) {
d3.select(this).attr('status'. function (d) { //[3]
return d.properties[propPicked] //[2] this is where I am stuck
})
})
任何想法?