让我们制作一张地图 Topojson 没有出现 - 没有错误消息但没有任何反应
Let's make a map Topojson doesn't appear - no error msgs but nothing happens
我想使用 D3 绘制巴西地图(州边界),但我失败了。该地图采用 Topojson 格式(它是 here) and I'm following Mike Bostock's tutorial. I can replicate the tutorial results exactly when plotting the UK (map here),但是当我尝试绘制巴西时没有任何反应 - 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
我想使用 D3 绘制巴西地图(州边界),但我失败了。该地图采用 Topojson 格式(它是 here) and I'm following Mike Bostock's tutorial. I can replicate the tutorial results exactly when plotting the UK (map here),但是当我尝试绘制巴西时没有任何反应 - 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