1
我有一个JSON文件,表明d3地图不是正在渲染我创建的澳大利亚地形图文件。D3地图无法渲染澳大利亚地图文件
相同的代码呈现美国地图就好了。浏览器检查器中没有错误,并且这两个地图都可以在像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>
谢谢!你知道为什么我可以渲染美国地图,但没有投影吗? – Dawid
原因是因为当你做'd3.geo.path();'投影是空的。 (对于美国的情况)功能值是这样的,你不需要缩放,所以不需要翻译它。我也编辑了我的答案,希望它解释得更好。 – Cyril