如何获取d3.js数据图支持的所有国家/地区的列表?
按照datamaps demo page中的示例,我将此配置用于我的地图:
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”等)?
答案 0 :(得分:8)
知道了!
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"}
答案 1 :(得分:4)
答案 2 :(得分: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