1
我嘗試在div中顯示我的地圖 - 但我希望將此地圖限制爲div尺寸 - 現在,它忽略w和h值以及vis css設置。d3地理地圖溢出
設置svg的高度和寬度是否有意義?當我把投影的比例放大時,它總會比組織的大。 SVG。
var w = 200;
var h = 300;
// this will attach a svg-element with the class "map" to "mydiv"
var map = d3.select("#mydiv").append("svg:svg")
.attr("width", w)
.attr("height", h)
.attr("class", "map");
var projection = d3.geo.albers()
.origin([10.5,51])
.scale(2000)
.translate([100, 150]);
var path = d3.geo.path().projection(projection);
d3.json('germany.json', function(json) {
map.selectAll('path')
.data(json.features)
.enter().append('path').attr('d', path);
});
和我的CSS:
#vis {
overflow: hidden;
width: 350px;
height: 220px;
}
#vis和#mydiv是兩個不同的DIV元素嗎? – mbostock 2012-08-19 17:57:58