topojson-client is a JavaScript library that decodes compact TopoJSON topology into GeoJSON data that D3 can read and manipulate. TopoJSON stores shared borders as single arcs, reducing file size and preventing duplicated strokes. section 13.1.2 section 13.5
Use the library’s conversion methods to prepare geographic layers:
- Call feature(topology, object) to extract GeoJSON features from a named topology object. section 13.5
- Call mesh(topology, object) to extract shared borders as a GeoJSON MultiLineString. section 13.5
- Pass the resulting features and borders to D3’s geographic path generator for SVG rendering. section 13.5
Draw departments from TopoJSON
Install the package with npm i topojson-client, then import it and extract named objects: const departments = topojson.feature(france, france.objects.FRA_adm2).features; const borders = topojson.mesh(france, france.objects.FRA_adm2); Render departments as paths and borders as one additional path. A Mercator projection and geoPath generator convert the geographic data into SVG path commands, while the single border path avoids overlap. section 13.5
Figure 13.3 While shared borders appear twice in GeoJSON, TopoJSON reduces redundancy by merging them into a single arc.
Compare duplicated GeoJSON borders with TopoJSON’s single shared arcs to understand the library’s compact representation. section 13.1.2
