2

我有一个世界地图的正交投影,在 D3 中并使用 TopoJSON。我通过调用此代码为每次加载数据的国家/地区着色。地球在不停地旋转。

我的问题是,在旋转过程中我收到错误消息:

错误

>> 错误:在 d3.v3.min.js:1 中解析 d="" >> 时出现问题

对于每个:

    .attr("d", path);

首先,我认为它取决于 topojson 脚本,因为有不同的版本。但它没有。

javascript代码:

初始化地球/投影的属性:

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);

    }

地球自转:

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));  

}); 
4

1 回答 1

3

这是一个已知的 WebKit 错误。我有同样的问题,它似乎不会以任何方式影响 svg 渲染。

超出 clipAngle 的任何内容都分配了 d="",我认为这应该是一个有效的空值,但会标记为错误。

于 2013-07-04T15:05:13.297 回答