Search code examples
jvectormap

Create a scale key for jvectormap region colors


I'd like to create a key to my map that shows the values associated with the different colors, as at the bottom of the drawing:

enter image description here

I can make a series of boxes easily enough. Is there a method somewhere I can input a value to get the color back that the map would use for that value?


Solution

  • First you need a map object. If you have created a map with jvm.WorldMap constructor you have it already, otherwise if you have created a map using jQuery wrapper you can do:

    var map = $('#map').vectorMap('get', 'mapObject');
    

    Then to convert the value to color do the following:

    var color = map.series.regions[0].scale.getValue(someValue);