d3.js.如何制作地图全宽?

时间:2015-06-03 19:47:47

标签: d3.js topojson

可用代码here。地图看起来像全宽,但根本没有。顶部和左侧和右侧都有一些凹痕。 d3.js地图的所有示例都使用scale method中的一些奇怪的幻数。我尝试使用this answer中的这些数字,但看起来我的情况并非如此。那么缩放地图的真正方法是什么?我希望在没有任何缩进的情况下使其全宽。

var body = d3.select("body").node().getBoundingClientRect();

var coef = 640 / 360;

var width = body.width;
var height = width / coef;

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

var projection = d3.geo.equirectangular()
  .rotate([-180, 0])
  .scale(width / 640 * 100)
  .translate([width / 2, height / 2])

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


d3.json("https://dl.dropboxusercontent.com/s/20g0rtglh9xawb8/world-50m.json?dl=1", function(error, world) {
  svg.append("path")
    .datum(topojson.feature(world, world.objects.land))
    .attr("d", path);
});

0 个答案:

没有答案
相关问题