openlayers 3 - Changes in a GeoJson file do not refresh on the map -


i create layer geojson file. made changes file , hope changes can reflected on map. map stays same.

i think should force map reload json file wonder how that.

i had same issue , how solved it:

consider using vector loader function handle fetching geojson files. i've had numerous caching issues not using vector loading function fetch geojson files , method below eliminated problem. example:

var utils = { refreshgeojson: function(source,url) {   var = date.now();   if (typeof url == 'undefined') {     url = source.geturl();   }   url += '?t=' + now; //add current time prevent browser caching   console.info('refreshgeojson url: ' + url);       this.getjson(url).when({     ready: function(response) {       var format = new ol.format.geojson();       var features = format.readfeatures(response, {         featureprojection: 'epsg:3857'       });       console.dir(features);       console.log(features.length);       source.addfeatures(features);       source.changed();     }      }); }, getjson: function(url) {       var xhr = new xmlhttprequest(),       when = {},       onload = function() {     console.log('xhr.status onload() ' + xhr.status);     if (xhr.status === 200) {      console.log('getjson() xhr: ');      console.dir(xhr);      console.log('getjson() xhr.response: ');      console.dir(xhr.response);               when.ready.call(undefined, json.parse(xhr.response));         }     if (xhr.status === 404) {       console.log('file not found! url: ' + url);       alert("file not found!\n" + url);     }       },       onerror = function() {         console.info('cannot xhr ' + json.stringify(url));       };   //console.log('getjson() - retrieve file url: ' + url);       xhr.open('get', url, true);       xhr.setrequestheader('cache-control', 'no-store');       xhr.onload = onload;       xhr.onerror = onerror;       xhr.send(null);       return {     when: function(obj) { when.ready = obj.ready; }     }; } };  var vectorloader = function(extent, resolution, projection) {   utils.refreshgeojson(this); }  var vectorsource = new ol.source.vector({     url: /path-to/myfile.geojson',     format: new ol.format.geojson({       defaultdataprojection :'epsg:3857'      }),     loader: vectorloader,     strategy: ol.loadingstrategy.all }); 

i have timed function calls vectorsouce.clear() before reloads data layer. calling .clear() fires vector loader function map layer.


Comments

Popular posts from this blog

How to get the arclen between two curve points in Maya? -

C++ Linked List -

git svn - Unignore directories in git-svn (adding directories to a sparse checkout) -