May 2019
Beginner to intermediate
650 pages
14h 50m
English
Since adjacent shapes share common borderlines in TopoJSON, it's easy to compute their neighbors. The topojson.neighbors() function receives an array of geometries and returns an array of arrays with the neighbors of each shape:
const neighbors = topojson.neighbors(object.geometries);
Each array inside the main array represents a shape, and their contents are array-indexes of the shapes that have common borders with them. This is made clearer in the following illustration, which compares an array of neighbors with the rendered shapes. You can see the code and run this example in TopoJSON/13-neighbors-shapes.html:

Read now
Unlock full access