繁体   English   中英

为什么不使用d3在Meteor [ubuntu]中加载此json文件?

[英]Why won't this json file load with d3 in Meteor [ubuntu]?

我正在尝试在ubuntu的Meteor中重现此d3世界之旅,但似乎d3没有正确加载json或其他内容。 我从几个不同的位置尝试过json和tsv文件: https : //github.com/KoGor/Maps.GeoInfo,https : //github.com/mapmeld/flightmap ,并尝试对文件执行fromdos 一切似乎都可以正常工作,只是在我尝试运行它时出现错误“ SyntaxError:Unexpected Token <”。 tsv和json文件位于/ public / geo中

我的js文件:

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}


if (Meteor.isClient) {
  Template.map.rendered = function() {
      var width = 960,
          height = 500;

      var projection = d3.geo.orthographic()
          .scale(248)
          .clipAngle(90);

      var canvas = d3.select("body").append("canvas")
          .attr("width", width)
          .attr("height", height);

      var c = canvas.node().getContext("2d");

      var path = d3.geo.path()
          .projection(projection)
          .context(c);

      var title = d3.select("h1");

      queue()
          .defer(d3.json, "/geo/world-110m.json")
          .defer(d3.tsv, "/geo/world-country-names.tsv")
          .await(ready);

      function ready(error, world, names) {
          if (error) return console.warn(error);
          var globe = {type: "Sphere"},
              land = topojson.feature(world, world.objects.land),
              countries = topojson.feature(world, world.objects.countries).features,
              borders = topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }),
              i = -1,
              n = countries.length;

          countries = countries.filter(function(d) {
              return names.some(function(n) {
                  if (d.id == n.id) return d.name = n.name;
              });
          }).sort(function(a, b) {
              return a.name.localeCompare(b.name);
          });

          (function transition() {
              d3.transition()
                  .duration(1250)
                  .each("start", function() {
                      title.text(countries[i = (i + 1) % n].name);
                  })
                  .tween("rotate", function() {
                      var p = d3.geo.centroid(countries[i]),
                          r = d3.interpolate(projection.rotate(), [-p[0], -p[1]]);
                      return function(t) {
                          projection.rotate(r(t));
                          c.clearRect(0, 0, width, height);
                          c.fillStyle = "#bbb", c.beginPath(), path(land), c.fill();
                          c.fillStyle = "#f00", c.beginPath(), path(countries[i]), c.fill();
                          c.strokeStyle = "#fff", c.lineWidth = .5, c.beginPath(), path(borders), c.stroke();
                          c.strokeStyle = "#000", c.lineWidth = 2, c.beginPath(), path(globe), c.stroke();
                      };
                  })
                  .transition()
                  .each("end", transition);
          })();
      }
  }
}

我如何才能正确加载json文件,或如何使示例在流星中工作?

请注意,您必须将.json(和.tsv)放入Meteor项目的公共文件夹中,因为它们是静态资产。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM