ol.source.getState()
doesn't seem to be reliable. When I call it on a vector source it returns ready, but the features are not available yet. Code looks like this:
var vectorSource = new ol.source.Vector({
url: 'world.topo.json',
format: new ol.format.TopoJSON()
});
// ... init map with vectorSource
console.log(vectorSource.getState()); // returns "ready"
console.log(vectorSource.getFeatureById("US")); // returns null
Any other way to see if a vector source is ready?
Best Answer
You can provide your own loader function and set some custom listeners, as it follows:
Set some custom listeners:
And a xhr function:
Working demo.