[GIS] OpenLayers3 Redraw MAP/Refresh

openlayers

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',
             lineDash:[1],
             width: 1
            })})


        });


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

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

        });
        map.renderSync(5000); 

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

Best Answer

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();
source.updateParams(params);
Related Question