Search code examples
javascriptjqueryjvectormap

Dynamically change object property


I'm using jVectorMaps. I have a map object with a backgroundColor property:

map = new jvm.Map({
    container: $('#map'),
    map: "world_mill_en,
    backgroundColor: bgcolor

Let's say I declare a global bgcolor variable. Then, I change the value of that variable at some point:

function changeBGcolor() {
    bgcolor = "yellow";
}

The idea is that the jVectorMap background color changes when I change the value of the bgcolor variable. So far I was not able to do it.

How can it be done?


Solution

  • You should use setBackgroundColor(). i.e.

    var bgColor = "red";
    var map = new jvm.Map({
      container: $('#map'),
      map: 'world_mill_en',
      backgroundColor: bgColor
    });
    
    bgColor = "yellow";
    
    map.setBackgroundColor(bgColor);
    

    See the documentation here for more information.