How to detect the loading end of a vector source in ol3?

3k views Asked by At

In OpenLayers 3, I want to detect when the features of a vector source are finished to be loaded inside a vector layer. Here's a snippet of the code I defined:

var vector = new ol.layer.Vector({
    source: new ol.source.Vector({
        url: '/path/to/file.json',
        format: new ol.format.GeoJSON()
    })
});

I've been looking for an event I could listen to on the ol.source.Vector but did not find any. Is there such a way to accomplish this?

Alternatives

I thought of alternative ways to accomplish this. Please, let me know if any of those make sense or if there are better ways to accomplish this.

Fetch the features myself

Instead of defining an url to the source, I could simply fetch the features myself using any asynchronous method from my preferred JavaScript library and act when the callback method is fired. Simple, but that kinda breaks the purpose of defining the 'url' and 'format' in the above snippet, which I find clean and simple.

Listen to the 'change' event ?

I see that the 'changed' method is called, which is defined in the ol.Object class. Is there a way I could use something related/around this ?

ol.featureloader

Okay, I would define an ol.featureloader instead of giving the 'url' and 'format' options, but then again I don't understand/know how I could listen to something from it either.

Any help would be greatly appreciated.

0

There are 0 answers