gpt4 book ai didi

d3.js - topojson V1 中的 topojson.object

转载 作者:行者123 更新时间:2023-12-04 03:04:29 24 4
gpt4 key购买 nike

我在玩 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com