プロパティの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>