海兰
我正在尝试使用来自geojson的d3.v3.js绘制svg。我从openstreetmap(我的测试数据:http ://pastebin.com/4GQne42i)中获取geojson,然后尝试将其呈现为svg。
我的JS代码:
var path, vis, xy, jdata;
xy = d3.geo.mercator().translate([0, 0]).scale(200);
path = d3.geo.path().projection(xy);
vis = d3.select("body").append("svg").attr("width", 960).attr("height", 600);
//22.json is the name of the file which contains the geojson data
d3.json("22.json", function(error, json) {
jdata = json;
if(error!=null)
console.log(error);
return vis.append("svg:g")
.selectAll("path")
.data(json.coordinates)
.enter().append("path")
.attr("d", path);
});
Run Code Online (Sandbox Code Playgroud)
而我的svg结果是这样的:
<svg width="960" height="600">
<g>
<path></path>
</g>
</svg>
Run Code Online (Sandbox Code Playgroud)
我知道投影效果不好,但是我认为svg应该有节点。
我的代码有什么问题?您会发布正确的解决方案吗?