Javascript D3地图-无法为印度地图应用合适的投影
我试图用D3地图绘制印度各州的地图(有争议的领土)。我成功地生成了topojson文件,该文件在 json链接是 但我没能画出地图。这个链接是我在JSFIDLE下所做的Javascript D3地图-无法为印度地图应用合适的投影,javascript,dictionary,d3.js,topojson,Javascript,Dictionary,D3.js,Topojson,我试图用D3地图绘制印度各州的地图(有争议的领土)。我成功地生成了topojson文件,该文件在 json链接是 但我没能画出地图。这个链接是我在JSFIDLE下所做的 var topoJsonUrl = "https://dl.dropboxusercontent.com/s/wk9qd47wn1nhsjm/dddtopo.json"; var width = 360, height = 360; d3.json(topoJsonUrl, function(error, mx) {
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';
});
});
该代码与其他国家(德国、墨西哥)合作得很好,但不确定为什么这次不起作用。任何帮助都将不胜感激。我不知道
topojson
在哪里初始化:`.selectAll(“path”).data(topojson.feature(mx,mx.objects.india).features);geoPaths.enter().append(“path”).attr(“d”,path);你似乎没有把地图的中心对准印度。您可以手动执行,也可以自动执行。看看这个,了解一下如何做到这一点。我已经把你的小提琴撞到了中心位置,我还认为你可能会感兴趣(试着点击左上角的文本)。@user1614080非常感谢。我想我应该从你的例子中学习如何正确地进行投影。这应该是正确的答案。你想“回答这个问题”,然后我可以把它标记为答案。