jvectorMap country colors
Asked Answered
S

4

5

I'd like to please view my source. I have problem: i need to change country colors, but colors: ... feature isn't working for me. Map is white and colors don't change.

Please answer. Thanks!

<script>
jQuery.noConflict();
jQuery(function(){
  var $ = jQuery;

  $('#focus').click(function(){
    $('#map1').vectorMap('set', 'focus', 'LT');
  });
  $('#map1').vectorMap({
    map: 'world_mill_en',
    focusOn: {
      x: 0,
      y: 0,
      scale: 1
    },
    colors:          {
                    IN:'#33250B',
                    dk:'#000FFF',
                    kp:'#33250b',
                    ir:'#3f4114',
                    iq:'#525252',
                    pk:'#654511',
                    uz:'#69681c',
                    tm:'#48470d',
                    eg:'#654906',
                    az:'#083803',
                    tj:'#410a0a',
                    kg:'#545353',
                    sy:'#654511',
                    jo:'#33250b',
                    kz:'#654511',
                    lk:'#525252',
                    US:'#000000',
                                     },
    series: {
      regions: [{
        scale: ['#C8EEFF', '#0071A4'],
        normalizeFunction: 'polynomial',

      }]
    }
  });
})

Smelser answered 17/10, 2012 at 12:8 Comment(2)
What version are you using? It seems that setting colors was supported in v0.2.3 jvectormap.com/documentation/javascript-api but not in v1.0 jvectormap.com/documentation/javascript-api-v1/jvm-worldmap.Wivinah
yes i recongnized it thanks! :)Smelser
B
13

If you use version 1.1.x then your code should look like this:

$('#map1').vectorMap({
    map: 'world_mill_en',
    focusOn: {
      x: 0,
      y: 0,
      scale: 1
    },
    series: {
      regions: [{
        values: {
            IN:'#33250B',
            dk:'#000FFF',
            kp:'#33250b',
            ir:'#3f4114',
            iq:'#525252',
            pk:'#654511',
            uz:'#69681c',
            tm:'#48470d',
            eg:'#654906',
            az:'#083803',
            tj:'#410a0a',
            kg:'#545353',
            sy:'#654511',
            jo:'#33250b',
            kz:'#654511',
            lk:'#525252',
            US:'#000000'
        }
      }]
    }
});
Bandaranaike answered 22/10, 2012 at 8:42 Comment(1)
I needed to capitalize ALL of the country letters for all to work. Thank you!Goldfarb
P
2

bjornd's solution works for 1.1x, however make sure the country codes are in CAPITALS as below or it will not work.

series: {
  regions: [{
    values: {
        IN:'#33250B',
        DK:'#000FFF',
        KP:'#33250b',
        IR:'#3f4114',
        IQ:'#525252',
        PK:'#654511',
        UZ:'#69681c',
        TM:'#48470d',
        EG:'#654906',
        AZ:'#083803',
        TJ:'#410a0a',
        KG:'#545353',
        SY:'#654511',
        JO:'#33250b',
        KZ:'#654511',
        LK:'#525252',
        US:'#000000'
    }
  }]
}
Poinciana answered 29/10, 2013 at 3:30 Comment(0)
P
0

You can set your own objects to fill the values, based on pre-determined or dynamic data (just make sure it is returned in the same format at 'US':'#0000000'. Be careful with the commas, they can be pesky little devils!

series: {
    regions: [{
        values: fillData,
        attribute: 'fill'
    },
  {
      values:opacityData,
      attribute: 'fill-opacity'
  }]
},
Pointenoire answered 31/7, 2014 at 16:29 Comment(0)
S
0
series: {
    regions: [{
        values: {
            'IN': '#3e9d01',
            'CA': '#4b93c1'
        },
        attribute: 'fill'
    }]
},
Sarmentose answered 24/4, 2016 at 17:19 Comment(1)
Could you please add some context? Where does this data structure go?Bitumen

© 2022 - 2024 — McMap. All rights reserved.