我有一个d3映射没有呈现我创建的澳大利亚TopoJSON文件的JSON文件。
同样的代码将美国地图绘制得很好。浏览器检查器中没有错误,这两种地图在geojson.io这样的在线可视化网站上都很好。
我提供了JSON的链接。
<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>
发布于 2016-07-12 02:27:20
问题在于您使用的是:
var path = d3.geo.path();
你没有给出投影:
var projection = d3.geo.mercator()
.scale(500)//scale it up as per your choice.
.translate([-900,0]);//translate as it was scaled up.
var path = d3.geo.path()
.projection(projection);
工作代码这里
https://stackoverflow.com/questions/38325752
复制