I'm very new to OpenLayers and all the GIS world.

I'm working with rasters (tiff that are converted to postgis sql)

I have this code:

        var feature;
            method: "POST",
            url: Routing.generate("getdpageometry"),
            dataType: 'json',
            data: { tipodpa:tipodpa, dpaid:object.id },
            async: false
        }).done(function( obj ) {
            feature = obj.feature;

        var formatWKT = new ol.format.WKT();
        var extentFeature = formatWKT.readFeature(object.extent, {
            dataProjection: 'EPSG:3857',
            featureProjection: 'EPSG:3857'
        var formatGeoJSON = new ol.format.GeoJSON();
        var feature = formatGeoJSON.readFeature(feature, {
            dataProjection: 'EPSG:32719',
            featureProjection: 'EPSG:32719'
        Store.vectorSource.addFeature( feature );
        Store.map.getView().fit(extentFeature.getGeometry().getExtent(), Store.map.getSize());

This is part of a code that is showing a map but only a region (defined by an extent in the database) is colored, and adds some blue border to it, like this:


What I need to do is change that blue color, I need it transparent, I only need the border to be blue, and also I would like to change the border color too, so my question is:

Where should I be looking to change those colors?

I'm pretty confused, not sure if it's possible to change it like a parameter, or it's OL3 library default color (I've search into the code, I have changed some blue code colors but nothing happens), or it has to be related with the raster from the database, or where/how...

Using the chosen answer, now my code has:

    this.state.vectorLayer = new ol.layer.Vector({
        source: this.state.vectorSource,
        style: new ol.style.Style({
            fill: new ol.style.Fill({  color: 'rgba(0, 0, 0, 0.2)'  }),
            stroke: new ol.style.Stroke({ color: '#FF0000',  width: 2  }),
            image: new ol.style.Circle({
                radius: 7,
                fill: new ol.style.Fill({
                    color: '#ffcc33'

And the map:

New map

1 Answer 1


See this example from the OpenLayers website and this question on SO:

You have to define a style variable and bind it to your layer:

var stroke = new ol.style.Stroke({
    color: 'rgba(255, 204, 0, 0)',
    width: 1,

var style = new ol.style.Style({
    stroke: stroke

vector = new ol.layer.Vector({
    source: vectorSource,
    style: style

But your code seems not complete (where is defined the layer?) so I'm not sure if it will fit in without extra modifications.

  • Thank you mate. Right, that code is part of the total code, kinda complex, (many Reactjs components). I'll have to put it all in pastebin if is necesary. I will try your answer.
    – pmiranda
    Commented Feb 8, 2017 at 16:12
  • Yes! it was so simple, but didn't know where to see, thanks you very much. I'll put my new code in my original question as UPDATE.
    – pmiranda
    Commented Feb 8, 2017 at 16:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.