Setting Vector Feature Fill Opacity when you have a hexadecimal color

Jonathan picture Jonathan · Jan 17, 2015 · Viewed 13.1k times · Source

I'm trying to set the fill opacity of a vector feature in OL3 and can't figure out how to do it if I have a hexadecimal value...I've seen examples with rgba. Any suggestions?

Here's what I have:

style : function(feature, resolution) {
          return [new ol.style.Style(
          {
            stroke : new ol.style.Stroke(
            {
              color : feature.get('color'),  
              width : 2
            }),
            fill : new ol.style.Fill(
            {
              color : feature.get('color'), //'#FF0000'
              opacity : 0.2   // I thought this would work, but it's not an option
            })
          })]
        }

Answer

wondim picture wondim · Jul 2, 2017

This is late but might help someone. Using rgba property is also possible.

fill: new ol.style.Fill({color: 'rgba(255, 255, 0, 0.63)'}),