我有一个世界地图的正交投影,在D3和通过使用TopoJSON。我通过调用此代码为每个加载数据着色国家。 地球不断旋转。D3.js解析错误 - 正交地图投影的旋转
我的问题是,在旋转我得到的错误信息:
错误
>>错误:问题解析d = “” >>在d3.v3.min.js:1
每个:
.attr("d", path);
首先,我认为这取决于topojson脚本,因为有不同的版本。但事实并非如此。
javascript代码:
INIT全球/投影的属性:
svg.append("defs").append("path")
.datum({type: "Sphere"})
.attr("id", "sphere")
.attr("d", path);
...
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
读取JSON和TSV的数据,并追加土地和国家:
queue()
.defer(d3.json, "world-110m.json")
.defer(d3.tsv, "world-country-names.tsv")
.await(ready);
function ready(error, world, names) {
var countries = topojson.feature(world, world.objects.countries).features,;
i = -1,
n = countries.length;
countries.forEach(function(d) {
var tryit = names.filter(function(n) { return d.id == n.id; })[0];
if (typeof tryit === "undefined"){
d.name = "Undefined";
console.log(d);
} else {
d.name = tryit.name;
}
});
var country = svg.selectAll(".country").data(countries);
country
.enter().insert("path", ".graticule")
.attr("id", function(d){
return "c" + d.id;
})
.attr("d", path);
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("d", path);
}
的旋转globe:
var velocity = .03,
then = Date.now();
d3.timer(function() {
var angle = velocity * (Date.now() - then);
projection.rotate([angle,0,0]);
svg.selectAll("path")
.attr("d", path.projection(projection));
});
用一大块代码很难在SO上得到很好的答案。你能缩小到引发错误的部分吗?哪条路遇到麻烦? – nrabinowitz
哦,对不起。现在,我删除了一些行,我确信没有错误,并将代码分成几部分。也许,现在,它更具可读性:/ – user123456789
好吧,所有对'.attr(“d”,path)“的调用都失败了?这表明你没有绑定你期望的数据 - 尝试在函数中封装'path',以便检查输入... – nrabinowitz