topojson
Pre-projected geometry v getting the browser to do it (aka efficiency v flexibility)
If I use this D3 function, aren’t I still forcing the viewer’s browser to do a lot of data processing, which will worsen the performance? The point of pre-processing the data is to avoid this. Or am I overestimating the processing work involved in the d3.geoTransform() function above? Short Answer: You are overestimating the amount … Read more
How to add properties to topojson file?
Try using this: topojson -o final.json -e data.tsv \ –id-property=code_2,code -p code_2,state=name \ — topojson.json Which should output: { “type”: “Topology”, “transform”: { “scale”: [ 0.000016880209206372492, 0.000007005401010148724 ], “translate”: [ -1.8418800213354616, 51.15278777877789 ] }, “objects”: { “states”: { “type”: “GeometryCollection”, “geometries”: [ { “type”: “Polygon”, “arcs”: [ [ 0 ] ], “id”: “AK”, “properties”: { … Read more
D3.js Map with Albers Projection: How to rotate it?
Albers projections can be a bit tricky if you don’t know the underlying transformations. Unless showing the US (for which the parameters of d3.geoAlbers are defaulted to), you’ll likely need to modify the parallels, rotation, and center. Standard Parallels This is an albers projection with its parallels set to 10 and 15 .parallels([10,15]), as in … Read more
D3js: Automatic labels placement to avoid overlaps? (force repulsion)
In my opinion, the force layout is unsuitable for the purpose of placing labels on a map. The reason is simple — labels should be as close as possible to the places they label, but the force layout has nothing to enforce this. Indeed, as far as the simulation is concerned, there is no harm … 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
My answer is close to Jan van der Laan’s, but you can simplify things slightly because you don’t need to compute the geographic centroid; you only need the bounding box. And, by using an unscaled, untranslated unit projection, you can simplify the math. The important part of the code is this: // Create a unit … Read more