Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blink (when refresh) and duplicate (when move) - Features on vector layer #4558

Closed
Bear4 opened this issue Dec 15, 2015 · 4 comments
Closed

Comments

@Bear4
Copy link

Bear4 commented Dec 15, 2015

I have a problem with refresh vector layer every X seconds. I was looking solutions many times without luck. I have code but with blink effect (blinking features, when I clear old and add new features):
[OL v 3.11.2]


var sourceVector = new ol.source.Vector({
loader: function(extent) {
$.ajax('http://server/wfs_ant',{
type: 'GET',
data: {
service: 'WFS',
version: '1.1.0',
request: 'GetFeature',
typename: 'v_wezel_rfid',
srsname: 'EPSG:3857',
bbox: extent.join(',') + ',EPSG:3857'
},
}).done(loadFeatures);
},
strategy: ol.loadingstrategy.bbox
});

var loadFeatures = function(response) {
formatWFS = new ol.format.WFS(),
//sourceVector.clear();
sourceVector.addFeatures(formatWFS.readFeatures(response));
console.log('loadFeatures');
};

function refresh(sourceVector){
sourceVector.clear();
sourceVector;
console.log(' refresh');
}

var layerVector = new ol.layer.Vector({
source: sourceVector,
style: vectorStyle
});
setInterval(function(){refresh(sourceVector); }, 10000);


I was trying remove: sourceVector.clear() in loadFeature section but then loading wfs features going on endless loop.
Second problem is duplicate features, when move map there show duplicate features and duplicate are add every move map. I have unique id on wfs.

@Bear4
Copy link
Author

Bear4 commented Dec 17, 2015

Duplicate features (at loading strategy bbox) problem omited by change:
from -> strategy: ol.loadingstrategy.bbox
to -> strategy: ol.loadingstrategy.tile(new ol.tilegrid.createXYZ())

What about blink at refresh layer? Is there any solution?

@ahocevar
Copy link
Member

When you have unique ids on your features, there should be no duplicates. Maybe double-check if they are really as fid when you get the data from your server.

The classic solution for avoiding blink effects is to use two sources, and switch from the old source to the new source when the features are loaded. And yes, call clear() on the source to trigger a reload.

Also, your code could be simplified by just using a url function instead of a loader.

@Bear4
Copy link
Author

Bear4 commented Dec 17, 2015

Use two sources and switch between... it's gently complicated, would be nice to have simpler solution.

Thx for new OL3

@ahocevar
Copy link
Member

It's not that complicated. Look at this fiddle: http://jsfiddle.net/ahocevar/tLt5wdpz/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants