jqueryjqvmap

jqvmap - applying color to multiple states/regions


With jquery and jqvmap, I'm setting multiple state colors in a US map. For instance, to color all the states that start with "A" red, this works:

jQuery('#vmap').vectorMap('set', 'colors', {al: 'red'});
jQuery('#vmap').vectorMap('set', 'colors', {ak: 'red'});
jQuery('#vmap').vectorMap('set', 'colors', {az: 'red'});
jQuery('#vmap').vectorMap('set', 'colors', {ar: 'red'});

is there a way to make that shorter? I'd like to do this:

var astates = ["al", "ak", "az", "ar"];
for (var i = 0; i < astates.length; ++i) {
    jQuery('#vmap').vectorMap('set', 'colors', { 'astates[i]' : 'red'}); 
}

But that doesn't seem to work. Thanks


Solution

  • var fc = 'red'; // you'll need this if you'll want to change the whole group color someday
    jQuery('#vmap').vectorMap('set', 'colors', {al: fc, ak: fc, az: fc, ar:fc});