[GIS] Setting fill style in polygon in OpenLayers

openlayers

I have created a polygon using Vector layer in OpenLayers 3 now I have to fill that polygon with red color. But I cannot do this using style option in OpenLayers 3.

Any one have any idea how to do this?

Best Answer

You must define a ol.styleStyle object, which again consist of an ol.style.Fill and an ol.style.Stroke object. In the OL3 documentation you must unclick the "Stable only" field in the upper right corner to see the full documentation.

_myStroke = new ol.style.Stroke({
   color : 'rgba(255,0,0,1.0)',
   width : 1    
});

_myFill = new ol.style.Fill({
   color: 'rgba(255,0,0,1.0)'
});

myStyle = new ol.style.Style({
   stroke : _myStroke,
   fill : _myFill
 });