3

Background: I have a single geoJSON data object that backs multiple Vector Layers of its features. I do this because the feature data has many attributes and can be presented in many different ways, and by having multiple layers, I can quickly switch between visualizations.

My issue comes into play when I update the data in the corresponding backing-data store. Since the features were only loaded once (Strategy.fixed), they do not see the updates to the underlying store, and instead retain the properties they were initially loaded with.

I was hoping there was a strategy or eventing mechanism already created that I can alert my layers that it's underlying data has changed and to refresh it's features as required. As of now, I have to either a) update each feature in each of my layers and then redraw those that changed or b) remove and add all the features on each of my layers for them to see the changes.

I imagine that the Refresh strategy could somehow be of assistance, but that would bring it's own issues (namely intervals instead of instant updates and the need more for more than just inline geojson object declarations).

Thanks for any help or suggestions.

1 Answer 1

4

One thing that you could do is long polling. Leave your HTTP connection open until something has changed, and then close it. This is easy with OpenLayers, using e.g. (untested):

layer.events.register("loadend", this, function() {
    layer.refresh({params: {poll: true}});
});

On the server, you would look at the request string, and if it has a poll param set to true, you would not close the request until something has changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.