openlayers 3 - Why vectorSource.clear() causes feature reload? -


i have ol.source.vector custom feature-loader. need replace existing features new ones. code inside loader:

vectorsource.clear(); vectorsource.addfeatures(features); 

the problem calling .clear() causes new feature loading , infinite loop result. load->clear->load->clear...

is normal behavior? how can clear features before add?

i tend think normal behavior. avoid infinite loop should call vectorsource.clear() outside loader , let know vectorsource emptied. change parameter on loader function.

since didn't show code enough, i'll suggest like:

var cleared = false; vectorsource.on('clear', function(evt){     cleared = true; }); 

and inside loader function:

loader: function(){      if(cleared) {         //some logic     } 

Comments