我的数据中有与国家相关联的数值。我已经为每个国家创建了缩放圆,并希望使用cx和cy将它们定位在每个国家的中心。
我使用topoJSON生成了一张地图,其中包含国家代码“ids”,而我的数据(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