Datamaps get list of country codes
Asked Answered
H

3

11

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

Hoiden answered 30/7, 2014 at 18:22 Comment(0)
H
11

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"} 
Hoiden answered 30/7, 2014 at 18:37 Comment(1)
if you do a console like: console.log(countries[i].id, countries[i].properties.name) you should see the 3 letter code as well as the name.Dragonnade
D
4

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

Dragonnade answered 31/7, 2014 at 16:19 Comment(1)
FYI these codes don't exactly correspond to what the API accepts/expectsSpurgeon
D
0

I've extracted all the country code data and put it into a CSV, it should be complete and the exact same being used in datamaps.

However, there is no country code for Kosovo, Northern Cyprus, and Somaliland. If you like to address them you have to use quotes. I don't know of any solution on how to address them individually.

"-99": { fillKey: "marked" }

All other countries are as follows:

AFG,Afghanistan
AGO,Angola
ALB,Albania
ARE,United Arab Emirates
ARG,Argentina
ARM,Armenia
ATA,Antarctica
ATF,French Southern and Antarctic Lands
AUS,Australia
AUT,Austria
AZE,Azerbaijan
BDI,Burundi
BEL,Belgium
BEN,Benin
BFA,Burkina Faso
BGD,Bangladesh
BGR,Bulgaria
BHS,The Bahamas
BIH,Bosnia and Herzegovina
BLR,Belarus
BLZ,Belize
BOL,Bolivia
BRA,Brazil
BRN,Brunei
BTN,Bhutan
BWA,Botswana
CAF,Central African Republic
CAN,Canada
CHE,Switzerland
CHL,Chile
CHN,China
CIV,Ivory Coast
CMR,Cameroon
COD,Democratic Republic of the Congo
COG,Republic of the Congo
COL,Colombia
CRI,Costa Rica
CUB,Cuba
-99,Northern Cyprus
CYP,Cyprus
CZE,Czech Republic
DEU,Germany
DJI,Djibouti
DNK,Denmark
DOM,Dominican Republic
DZA,Algeria
ECU,Ecuador
EGY,Egypt
ERI,Eritrea
ESP,Spain
EST,Estonia
ETH,Ethiopia
FIN,Finland
FJI,Fiji
FLK,Falkland Islands
FRA,France
GUF,French Guiana
GAB,Gabon
GBR,United Kingdom
GEO,Georgia
GHA,Ghana
GIN,Guinea
GMB,Gambia
GNB,Guinea Bissau
GNQ,Equatorial Guinea
GRC,Greece
GRL,Greenland
GTM,Guatemala
GUY,Guyana
HND,Honduras
HRV,Croatia
HTI,Haiti
HUN,Hungary
IDN,Indonesia
IND,India
IRL,Ireland
IRN,Iran
IRQ,Iraq
ISL,Iceland
ISR,Israel
ITA,Italy
JAM,Jamaica
JOR,Jordan
JPN,Japan
KAZ,Kazakhstan
KEN,Kenya
KGZ,Kyrgyzstan
KHM,Cambodia
KOR,South Korea
-99,Kosovo
KWT,Kuwait
LAO,Laos
LBN,Lebanon
LBR,Liberia
LBY,Libya
LKA,Sri Lanka
LSO,Lesotho
LTU,Lithuania
LUX,Luxembourg
LVA,Latvia
MAR,Morocco
MDA,Moldova
MDG,Madagascar
MEX,Mexico
MKD,Macedonia
MLI,Mali
MMR,Myanmar
MNE,Montenegro
MNG,Mongolia
MOZ,Mozambique
MRT,Mauritania
MWI,Malawi
MYS,Malaysia
NAM,Namibia
NCL,New Caledonia
NER,Niger
NGA,Nigeria
NIC,Nicaragua
NLD,Netherlands
NOR,Norway
NPL,Nepal
NZL,New Zealand
OMN,Oman
PAK,Pakistan
PAN,Panama
PER,Peru
PHL,Philippines
PNG,Papua New Guinea
POL,Poland
PRI,Puerto Rico
PRK,North Korea
PRT,Portugal
PRY,Paraguay
QAT,Qatar
ROU,Romania
RUS,Russia
RWA,Rwanda
ESH,Western Sahara
SAU,Saudi Arabia
SDN,Sudan
SSD,South Sudan
SEN,Senegal
SLB,Solomon Islands
SLE,Sierra Leone
SLV,El Salvador
-99,Somaliland
SOM,Somalia
SRB,Republic of Serbia
SUR,Suriname
SVK,Slovakia
SVN,Slovenia
SWE,Sweden
SWZ,Swaziland
SYR,Syria
TCD,Chad
TGO,Togo
THA,Thailand
TJK,Tajikistan
TKM,Turkmenistan
TLS,East Timor
TTO,Trinidad and Tobago
TUN,Tunisia
TUR,Turkey
TWN,Taiwan
TZA,United Republic of Tanzania
UGA,Uganda
UKR,Ukraine
URY,Uruguay
USA,United States of America
UZB,Uzbekistan
VEN,Venezuela
VNM,Vietnam
VUT,Vanuatu
PSE,West Bank
YEM,Yemen
ZAF,South Africa
ZMB,Zambia
ZWE,Zimbabwe
Dett answered 26/1, 2020 at 16:50 Comment(2)
Is this exhaustive?Deoxyribonuclease
@Nelles I would say yes. However, the country code of Kosovo, Northern Cyprus and Somaliland is "-99" and therefore can‘t be accessed individually. When you try to address all of the lands you shouldn't forget about the quotes, I will update my first replyDett

© 2022 - 2024 — McMap. All rights reserved.