您可以使用world_mill_en
地图和name
属性中的国家名称值生成以国家名称为键的新地图:
//Clone the world map that uses ISO-2 keys
var countriesByName = $.extend(true, {}, jvm.WorldMap.maps['world_mill_en']);
countriesByName.paths = {}; //clear the paths
$.each(jvm.WorldMap.maps['world_mill_en'].paths, function(key, obj){
//create new path entries, keyed by the country name
countriesByName.paths[obj.name] = obj;
});
//Add this new data map, to be loaded
$.fn.vectorMap('addMap', 'world_mill_en_byName',countriesByName);
然后加载键控国家名称的数据并引用新创建的地图:
//data with country name as key
var gdpData = {
"United States of America": 25,
"Canada": 50,
"Russia": 100,
"Angola": 200,
"Argentina": 400
};
$(function() {
$('#map').vectorMap({
map: 'world_mill_en_byName', //load up the map with country name as key
backgroundColor: '#eeeeee',
regionStyle: {
initial: {
fill: '#cccccc'
}
},
series: {
regions: [{
values: gdpData,
scale: ['#C8EEFF', '#0071A4'],
min: 0,
max: 400,
normalizeFunction: 'polynomial'}]
},
hoverOpacity: 0.7,
hoverColor: false
});
var mapObj = $('#map').vectorMap('get', 'mapObject');
var steps = 4;
for (var i = 0; i <= steps; i++) {
var val = 400 / steps * i;
var color = mapObj.series.regions[0].scale.getValue(val);
$('#key').append('<div style="background-color:' + color + ';">' + val + ' - ' + color + '</div>');
}
});
适用于您发布的 jsfiddle:http: //jsfiddle.net/hansenmc/fkRnC/8/ </p>