Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datamaps get list of country codes

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.)?

like image 951
SeanPlusPlus Avatar asked Jul 30 '14 18:07

SeanPlusPlus


2 Answers

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"} 
like image 136
SeanPlusPlus Avatar answered Nov 20 '22 03:11

SeanPlusPlus


Here is a list of the ISO-3166-1 3 letter country codes for reference.

like image 4
markmarkoh Avatar answered Nov 20 '22 03:11

markmarkoh