我在玩 topojson 时玩得很开心,但在 topojson 的 V1 中似乎没有定义 topojson.object,而在 V0 中支持它。有人可以解释我如何解决这个问题吗?我正在尝试为格式为 topojson 的输入文件中的每个多边形绘制不同的路径元素。代码是:
d3.json("maTopo.json", function(error, ma) {
svg.selectAll(".subunit")
.data(topojson.object(ma, ma.objects.ma).geometries)
.enter().append("path")
.attr("class", function(d) { return "subunit " + d.id; })
.attr("d", path);
});
最佳答案
您可以使用 topojson.feature
反而。
d3.json("maTopo.json", function(error, ma) {
svg.selectAll(".subunit")
.data(topojson.feature(ma, ma.objects.ma).features)
.enter().append("path")
.attr("class", function(d) { return "subunit " + d.id; })
.attr("d", path);
});
可以在此处找到详细示例:http://bost.ocks.org/mike/map/
关于d3.js - topojson V1 中的 topojson.object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16739712/