我想用 D3.js 画出柏林(德国)的轮廓。
我使用的柏林 geoJSON 文件是这个(柏林-“bundesländer”): http ://opendatalab.de/projects/geojson-utilities/
但它不适用于我的 .json 文件。我无法发现这个 .json 文件与我们州的不同之处,它使用完全相同的代码工作得很好: http ://examples.oreilly.com/0636920026938/chapter_12/us-states.json
我还尝试完全复制 us-states 文件,删除除一个之外的所有“功能”条目,然后仅将左侧的坐标数组替换为我的文件的坐标数组。但是萤火虫告诉我路径的元素根本没有“d”属性。
我真的很感激任何提示。先感谢您!
/* 我使用默认的 albersUsa 投影。如果我将路径定义为: d3.geo.path().projection(null) 会添加一些路径元素。但是,如果这是解决方案,我该如何翻译该路径?*/
var path = d3.geo.path();
d3.json("data/berlinBundeslaender_simplify2000.json",function(geoJson){
var color1 = d3.scale.category20();
mainSVG.selectAll("path")
.data(geoJson.features)
.enter()
.append("path")
.attr("d",path)
.attr("fill",function(d,i){return color1(i);});
});