Openlayers 3 vector source issue -


inside ajax callback have features expected, don't have them outside.

what 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()); // work }); console.log(geojsonsource.getfeatures()); // doesn't work 

everything's fine snippet. @kryger said, ajax asynchronous javascript , xml. so, register listener know when features added source, like:

geojsonsource.on('addfeature', function(event){     console.log(geojsonsource.getfeatures());  }); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -