I created a function to search for php to postgis and believe me that this function a file with the coordinates in the search GeoJSON format.

The problem is that when I do rendering the map and add the table when the query again takes this layer is not updated, you need to update your browser to see the change.

There any way to make it automatically change or refresh the map every time a query is made?

Here 's the code:

        var Vector= new ol.layer.Vector({
              source: new ol.source.Vector({
                projection: 'EPSG:3857',
                url: 'coordenadas.GeoJSON', // File created in php code
                format: new ol.format.GeoJSON()
              style:  new ol.style.Style({
             stroke: new ol.style.Stroke({
             color: 'red',
             width: 1


            var map = new ol.Map({
            target: 'map',
            layers: [ 
                new ol.layer.Tile({
                    source: new ol.source.BingMaps({
                    imagerySet: 'Aerial',

            view: new ol.View({
            center : ol.proj.transform([-0.33126,39.569658],'EPSG:4326','EPSG:3857'),
            zoom: 13


the map.renderSync () function; not how it works, I find documentation to understand its operation.

1 Answer 1


I've finally found a solution to refresh a layer on openlayers 3.

You have to update params of the layer source like this:

var source = yourLayer.getSource();
var params = source.getParams();
params.t = new Date().getMilliseconds();
  • This is a cache problem... because you are adding a unique parameter to url. This question is very similar to your: stackoverflow.com/questions/22744112/ol3-force-redraw-layer
    – Taber
    Commented Oct 19, 2015 at 11:39
  • 3
    TypeError: source.getParams is not a function ... Why?
    – Magno C
    Commented Jun 21, 2016 at 16:28
  • I have the same error as Magno C's
    – yo_haha
    Commented Aug 12, 2016 at 10:01
  • source.getParams is not for vector layers. Try source.refresh() Commented Feb 15, 2018 at 14:20

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.