topojson / D3 / Map with longitude + latitude
In a TopoJSON, those numbers in the coordinates
are not the actual latitude/longitude values. They have to be transformed. This function transforms the quantized topology to absolute coordinates:
function transformPoint(topology, position) { position = position.slice(); position[0] = position[0] * topology.transform.scale[0] + topology.transform.translate[0], position[1] = position[1] * topology.transform.scale[1] + topology.transform.translate[1] return position;};
You'll find the scale
and translate
at the end of the TopoJSON you linked:
"transform": {"scale": [0.000818229038834542,0.0005946917122888551], "translate":[-6.418556211736409,49.8647494628352] }
Based on that function, I believe it's easy to write a function that does the reverse:
function transformPointReversed(topology, position) { position = position.slice(); position[0] = (position[0] - topology.transform.translate[0]) /(topology.transform.scale[0]), position[1] = (position[1] - topology.transform.translate[1]) /(topology.transform.scale[1]) return position;};
I tried this function I just made and your London coordinates returned me this array:
[7688.309645789168, 2762.1059840278253]
Please, test it in your coordinates
to see if it works.
An alternative is overlaying your TopoJSON with a GeoJSON, which does use an absolute coordinates system.
Here is the API reference: https://github.com/mbostock/topojson-specification/blob/master/README.md#22-geometry-objects