D3.js Drawing geojson incorrectly

The issue is the winding order of the coordinates (see this block). Most tools/utilities/libraries/validators don’t really care about winding order because they treat geoJSON as containing Cartesian coordinates. Not so with D3 – D3 uses ellipsoidal math – benefits of this is include being able to cross the antimeridian easily and being able to select … Read more

Scaling d3 v4 map to fit SVG (or at all)

Why the data doesn’t project properly The key issue is that your data is already projected. D3 geoProjections use data that is unprojected, or in lat long pairs. Data in the WGS84 datum. Essentially a d3 geoProjection takes spherical coordinates and translates them into planar cartesian x,y coordinates. Your data does not conform to this … Read more

Center a map in d3 given a geoJSON object

With d3 v4 or v5 its getting way easier! var projection = d3.geoMercator().fitSize([width, height], geojson); var path = d3.geoPath().projection(projection); and finally g.selectAll(‘path’) .data(geojson.features) .enter() .append(‘path’) .attr(‘d’, path) .style(“fill”, “red”) .style(“stroke-width”, “1”) .style(“stroke”, “black”); Enjoy, Cheers