【发布时间】:2016-11-14 12:15:43
【问题描述】:
我有一个 d3 地图未呈现我创建的澳大利亚 TopoJSON 文件的 JSON 文件。
相同的代码可以很好地呈现美国地图。浏览器检查器中没有错误,并且两张地图都可以在 geojson.io 等在线可视化网站上正常呈现。
我提供了指向 JSON 的链接。
- Australian TopoJSON 不适用于我的代码(但适用于 geojson.io/#map=4/-27.97/125.22)
- American TopoJSON 可以使用我的代码
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<style>
path {
fill: #ccc;
}
</style>
</head>
<body>
<h1>topojson simplified Australia</h1>
<script>
var width = window.innerWidth,
height = window.innerHeight;
var path = d3.geo.path();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("topo-australia-simplified.json", function(error, topology) {
if (error) throw error;
svg.selectAll("path")
.data(topojson.feature(topology, topology.objects.australia).features)
.enter().append("path")
.attr("d", path);
});
</script>
</body>
</html>
【问题讨论】: