I want to make my d3 map fit to a svg container created with dynamic width and height attributes. It works so far by using the following code:
var height = $("#map-container").height(),
width = height * 0.9;
var svg = d3.select("#map-container")
.append("svg")
.attr("width",width)
.attr("height",height);
d3.queue()
.defer(d3.json,"./data/simplified20.json")
.await(drawMap);
function drawMap(error,bw) {
if (error) throw error;
var features = bw.features;
var projection = d3.geoMercator()
.rotate([-8.673659631519788,0])
.center([0,48.70015318963632])
.scale(height * 10.5)
.translate([width / 1.8, height / 1.5]);
var path = d3.geoPath().projection(projection);
var map = svg.append("g")
.attr("id","karte-rdb");
map
.selectAll("path")
.data(features)
.enter().append("path")
.attr("d", path)
}
If I replace the projection functions with fitSize(), my path is rendered with NaN values.
var projection = d3.geoMercator()
.fitSize([width,height],features);
Heres a sample of my geojson. It is unprojected data with lon-lat-pairs.
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[7.5219,
49.67881],
[7.50952,
49.67636],
...
Can't find my mistake so far. Thanks in advance!