0

I'm using this plugin on my website, which works great. You can pass a parameter for state specific styles, it looks like this:

$('#map').usmap({

    showLabels: false,
    stateStyles: {
        fill : '#ffffff',
        stroke : '#4f4f4f',
        'stroke-width' : 4,
    },

    stateHoverStyles: {
        fill : '#ffffff'
    },

    stateSpecificStyles: {
        'IN': {
            fill : '#84b8e7'
        },

        'CA': {
            fill : '#84b8e7'    
        },

        'TX': {
            fill : '#84b8e7'    
        }
    },

    stateSpecificHoverStyles: {

        'IN': {
            fill : '#0972ce'    
        },

        'CA': {
            fill : '#0972ce'    
        },

        TX': {
            fill : '#0972ce'    
        }
    }
});

I would like to fill in those state styles dynamically from an array that looks like ["CA", "IN", "TX"]. Is this possible?

2
  • Yes, it is possible! If you share your relevant code/efforts the community is much more likely to assist you =) (please see stackoverflow.com/help/mcve and stackoverflow.com/help/how-to-ask) Commented Jul 26, 2016 at 18:47
  • Will do, thanks. I made some efforts on my own but figured they'd pretty much just be nonsense. I'll post them next time, though. Commented Jul 26, 2016 at 18:58

1 Answer 1

1

If you're just looking for a way to create an object that looks like that, this snippet will do it for you. Let us know more about what you have/need, and I can expand this.

var arr = ['CA', 'IN', 'TX'], // Your state vars
    output = [];

arr.forEach(function(el) {
  output[el] = {
    fill: '#000000' // Could come from the same array, if needed
  };
)};
            
console.log(output);

Sign up to request clarification or add additional context in comments.

1 Comment

No problem! Let me know if you have any other questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.