Inside the ajax callback I have all the features as expected, but I don't have them outside.
What am I missing ?
var geojsonSource = new ol.source.Vector();
$.ajax('assets/data/data.geojson').then(function(response) {
var geojsonFormat = new ol.format.GeoJSON();
var features = geojsonFormat.readFeatures(response, {featureProjection: 'EPSG:4326'});
geojsonSource.addFeatures(features);
console.log(geojsonSource.getFeatures()); // this work
});
console.log(geojsonSource.getFeatures()); // this doesn't work