Although this globe is quite impressive for the amount of code used to create it, it feels a little dull. Let's differentiate the countries a little more, and also add the lines of latitude and longitude.
We can color the countries on the globe using a d3.scale.category20()
color scale. But we can't simply rotate through the colors, as there will be cases where adjacent countries will be filled with the same color.
To avoid this, we will take advantage of another function of TopoJSON, topojson.neighbors()
. This function will return, given a set of geometries (like the countries), a data structure that identifies which geometries are adjacent to each other. We can then utilize this data to prevent the potential problem with colors.
The process is demonstrated in the following example:
Note
bl.ock (12.12): http://goo.gl/9UimER
The projection in this example remains the same. The remainder of the code is changed.
We start by using the same projection...