[英]Let's make a map Topojson doesn't appear - no error msgs but nothing happens
我想使用D3繪制巴西地圖(州邊界),但失敗了。 該地圖為Topojson格式( 在此處 ),我正在關注Mike Bostock的教程 。 我可以(地圖繪制英國時正好復制教程結果在這里 ),但是當我嘗試繪制巴西沒有任何反應-有在JavaScript控制台中沒有錯誤消息。
這是我的代碼:
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 1160;
var projection = d3.geo.albers()
.center([0, 55.4])
.rotate([4.4, 0])
.parallels([50, 60])
.scale(1200 * 5)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
/*
PLOTTING THE UK WORKS
d3.json("uk.json", function(error, uk) {
console.log(uk)
svg.append("path")
.datum(topojson.feature(uk, uk.objects.subunits))
.attr("d", path);
});
*/
/* PLOTTING BRAZIL DOESN'T WORK */
d3.json("br-states.json", function(error, uf) {
console.log(uf)
svg.append("path")
.datum(topojson.feature(uf, uf.objects.states))
.attr("d", path);
});
</script>
</body>
必須根據您的需要更改以下內容。
// England viewport
var projection = d3.geo.albers()
.center([0, 55.4])
.rotate([4.4, 0])
.parallels([50, 60])
.scale(1200 * 5)
.translate([width / 2, height / 2]);
目前放大英格蘭地區:)
諸如此類:
// somewhere in South america
var projection = d3.geo.mercator() // albers may fails for Brazil
.center([-40, -30]) // country center
.rotate([4.4, 0]) //???? Check the api and edit for Brazil
.parallels([0, -60]) // ???
.scale(400) // smaller num = smaller Earth
.translate([width / 2, height / 2]); // topojson data is initially centered aroun x:0,y:0. This put back into the viewbox
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.