所以这里是我第一次使用D3的库来创建美国县的地图。使用topojson和D3映射数据
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://unpkg.com/[email protected]"></script>
<svg width="960" height="600"></svg>
<script>
'use strict';
let path = d3.geoPath();
let svg = d3.select("svg");
d3.queue()
.defer(d3.json, "https://d3js.org/us-10m.v1.json")
.await(ready)
function ready(error, us) {
if (error) throw error;
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.enter().append("path")
.attr("d", path)
}
简单而直截了当。有用。但是,当我将src更改为更好的json,并在每个县对象的道具中使用名称时:
d3.queue()
.defer(d3.json, "https://gist.githubusercontent.com/NealTaylor715/a08cc300e661aa45c464fa1e553b6f33/raw/eaa03db6827f2d6435b3898cae6fba03d6f55956/USCounties.json")
.await(ready);
地图中断。我得到一个空白的SVG与这个小灰色污点。奇怪的是数据附加到路径上,而不是我认为它应该的方式。任何指针?我的新JSON格式不正确。对象的属性属性的名称是我拍摄的功能的必要条件。任何帮助将不胜感激。先谢谢你。