【发布时间】:2016-03-09 11:13:24
【问题描述】:
在我的数据中,我有与国家相关的值。我为每个国家/地区创建了比例圆圈,现在想使用 cx 和 cy 将它们定位在每个国家/地区的中心。
我使用具有国家代码“ids”的 topoJSON 生成了一个地图,并且我的数据 (cd) 中有匹配的国家代码。
{"type": "Polygon",
"id": 604,
"arcs": [
[133, -473, -448, -378, -374, -413]
]
},
使用 D3 的path.centroid(feature),如何找到每个 topoJSON 路径的质心?
g.selectAll("circle")
.data(cd)
.enter()
.append("circle")
.attr("class", "bubble")
.attr("cx", 50)
.attr("cy", 50)
.attr("r", function(d) {
return r(+d.Value)
})
g.selectAll("path")
.data(topojson.object(topology, topology.objects.countries)
.geometries)
.enter()
.append("path")
.attr("d", path)
完整代码在这里Plunker
【问题讨论】: