Reputation: 21
I am looking for a method that redraws all the features stored in a layer (equivalent to method "redraw" with OL2)
the method "changed" of class ol.layer.Vector "refreshes" only the features visible on a map (for instance in the zoomed part) and thus doesn't impact the features outside
the treatment applied to those data is to delete periodically old features
how can I achieve this ?
another question is how to be notified of the end of this specific deletion ?
thanks in advance
Jean-Marie
Upvotes: 0
Views: 2714
Reputation: 21
first thanks for your answers
my question requires effectively more information :
the browser client receives points through a real time websocket connection
every second, an array of new features collected from those points is added into the Vector layer in this way :
vectorLayer.getSource().addFeatures(features);
the duration of the source buffer is, for instance one hour, and to manage a temporal sliding window of one hour, old features are removed every minute
map.once('postrender',removeOldFeatures);
vectorLayer.changed(); or map.renderSync();
this removal is only correctly done for visible features
But as soon as some features are not visible due, for instance, to a zoom on a portion of the map where those features are not displayed, then the removal treatment (removeOldFeatures) is not executed for those features whatever the method used (vectorLayer.changed() or map.render()) as a consequence the number of features doesn't stop increasing...
Jean-Marie
Upvotes: 1
Reputation: 123
I had the same problem with a TileVector Source and format GeoJSON. At the end i use the provided TileUrlFunction and to redraw the layer, i just set the Source again with the layer.setSource(yourdefinedSource) method. Dube is right. Most of the time (if the source is updated to often) it is useful to send a unique param (like unix timestamp) as a cachebuster.
Upvotes: 0