我有一個世界地圖的正交投影,在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