svg - 在 d3.js 地理 map 中如何在每个国家/地区创建一个圆圈?

标签 svg d3.js topojson

我是 d3.js 的新手.我被创建了一个world map使用json(geojson)在 d3 中。

现在我想创建一个单独的 svg circle每个 country .我不知道如何创建。请帮助任何人。我在下面添加了我的 fiddle 链接。请看一下并帮助我。谢谢

我的 fiddle 链接 - http://jsfiddle.net/sam0kqvx/18/

最佳答案

使用投影(d3.geo.centroid(d));:

svg.selectAll(".dots")
  .data(topojson.feature(world, world.objects.countries).features)
  .enter()
  .append("circle")
  .attr("r","6")
  .attr("fill","black")
  .attr("transform",function(d){                 
    var p = projection(d3.geo.centroid(d)); //<-- centroid is the center of the path, projection maps it to pixel positions
    return "translate("+p+")";
  });

已更新fiddle .

关于svg - 在 d3.js 地理 map 中如何在每个国家/地区创建一个圆圈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28507507/

相关文章:

css - 使用 feColorMatrix 匹配 SVG 中的颜色

javascript - 通过坐标在 Opera 的 SVG 中定位元素

javascript - d3.js 根据数据值附加不同的 SVG 元素

map - 使用跨越第 180 个子午线的传单显示 GeoJSON

javascript - 将 div 移动到 svg map 上的坐标

javascript - 使用 D3.js 的分层力图

javascript - d3.js 根据过滤器更改节点及其传出和传入链接的不透明度

angular - 使用 d3-brush 时鼠标按下时出错 : Cannot read property 'touches' of null

javascript - 如何避免 TopoJSON 内存错误

d3.js - 使用 topojson 映射美国邮政编码时出错