A geo path generator converts geographic data into SVG path descriptions. Configure it with a projection, then pass GeoJSON features to produce each path’s d attribute. section 13.2.1 section 13.7
Build a D3 map in three steps:
- Choose and configure a projection such as geoEqualEarth or geoMercator. section 13.2.1
- Initialize geoPath and connect it to the projection. section 13.2.1
- Bind geographic features to SVG path elements and assign the generator to d. section 13.2.1
Rendering a world map
const projection = d3.geoEqualEarth() .translate([width / 2, height / 2]) .scale(220); const geoPathGenerator = d3.geoPath() .projection(projection); svg.selectAll(".country-path") .data(world.features) .join("path") .attr("d", geoPathGenerator);
With TopoJSON, decode features and shared borders first; the same generator can draw department paths and a separate border path without duplicated strokes. section 13.5
const projection = d3.geoEqualEarth() .translate([translationX, translationY]) .scale(factor); const geoPathGenerator = d3.geoPath() .projection(projection);
Inspect the compact projection-and-generator setup used before binding geographic data to paths. section 13.2.1
A configured geoPath can also draw vector data on Canvas through path.context; this improves performance by avoiding DOM elements but removes direct image interaction. section 13.6.2
