How do I get a list of all countries supported by d3.js datamaps?
Following the example from the datamaps demo page, I am using this configuration for my map:
var basic = new Datamap({
element: document.getElementById("basic")
fills: {
defaultFill: "#ABDDA4",
authorHasTraveledTo: "#fa0fa0"
},
data: {
USA: { fillKey: "authorHasTraveledTo" },
JPN: { fillKey: "authorHasTraveledTo" },
ITA: { fillKey: "authorHasTraveledTo" },
CRI: { fillKey: "authorHasTraveledTo" },
KOR: { fillKey: "authorHasTraveledTo" },
DEU: { fillKey: "authorHasTraveledTo" },
}
});
How do I get a list of all countries included in datamaps (in addition to "USA", "JPN", "ITA", etc.)?
Got it!
var countries = Datamap.prototype.worldTopo.objects.world.geometries;
for (var i = 0, j = countries.length; i < j; i++) {
console.log(countries[i].properties);
}
// > Object {name: "South Africa"}
// > Object {name: "Zambia"}
// > Object {name: "Zimbabwe"}
Here is a list of the ISO-3166-1 3 letter country codes for reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With