10

如何获取 d3.js 数据地图支持的所有国家/地区的列表?

按照datamaps 演示页面中的示例,我将这个配置用于我的地图:

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" },
  }
});

如何获取数据地图中包含的所有国家/地区的列表(除了“USA”、“JPN”、“ITA”等)?

4

3 回答 3

10

知道了!

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"} 
于 2014-07-30T18:37:28.820 回答
4

以下是供参考的 ISO-3166-1 3 字母国家代码列表

于 2014-07-31T16:19:02.473 回答
0

我已经提取了所有国家代码数据并将其放入 CSV,它应该是完整的,并且与数据图中使用的完全相同。

但是,科索沃、北塞浦路斯和索马里兰没有国家代码。如果你想解决它们,你必须使用引号。我不知道如何单独解决它们的任何解决方案。

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

所有其他国家如下:

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
于 2020-01-26T16:50:18.053 回答