我试图通过D3 Map绘制印度地图(有争议的地区)。我成功生成了topojson文件,该文件在http://www.mapshaper.org/
中看起来不错json链接是https://dl.dropboxusercontent.com/s/wk9qd47wn1nhsjm/dddtopo.json
但是我没能画出地图。链接http://jsfiddle.net/sEFjd/47/就是我在jsfiddle下的做法。
var topoJsonUrl = "https://dl.dropboxusercontent.com/s/wk9qd47wn1nhsjm/dddtopo.json";
var width = 360,
height = 360;
d3.json(topoJsonUrl, function(error, mx) {
var projection = d3.geo.mercator();
// create the path
var path = d3.geo.path().projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
console.log(mx);
var geoPaths = svg.append("g")
.attr("class", "municipalities")
.selectAll("path")
.data(topojson.feature(mx, mx.objects.india).features);
geoPaths.enter().append("path")
.attr("d", path);
var p= svg.append("path")
.datum(topojson.mesh(mx, mx.objects.india))
.attr("d", path)
.attr("class", "state-boundary");
geoPaths.style("fill", function(d) {
return Math.random() > 0.5 ?'gray' : 'blue';
});
});
该代码适用于其他国家(德国,墨西哥)不确定为什么它这次不起作用。任何帮助将非常感激。