JVectorMap: set a region fill color programmatically

318 Views Asked by At

I have a simple JVector world map, initialized as below. What I'd like to do is to change the fill color of a desired region programmatically, via jQuery. I've been looking at this example https://jvectormap.com/examples/random-colors/ but I'm getting "this.scale is not set" error for my map and besides I want to alter the fill color after the map initialization, not during it.

PS. I can get the regions's initial fill color like this, but I have no idea how to alter it:

map.regions.US.element.shape.style.initial.fill

var map = new jsVectorMap({
      map: "world",
      selector: "#world_map",
      zoomButtons: true,
      markers: markers,
      markerStyle: {
        initial: {
          r: 9,
          strokeWidth: 7,
          stokeOpacity: .4,
          fill: window.theme.primary
        },
        hover: {
          fill: window.theme.primary,
          stroke: window.theme.primary
        }
      },
      zoomOnScroll: false
    });
    window.addEventListener("resize", () => {
      map.updateSize();
    });
1

There are 1 best solutions below

1
Francarlos Blanco On

me paso lo mismo y para resolverlo tuve que investigar y revisando los elementos encontre la forma

The same thing happened to me and to solve it I had to investigate and reviewing the elements I used this code to fix the problem.

map.regions.US.element.setStyle("fill", "red");