I'm loading an external geojson file with the next code:

var sourceTour2016 = new ol.source.Vector({
      url: 'tourdefrance_2016.geojson',
      format: new ol.format.GeoJSON()

  var layerTour2016 = new ol.layer.Vector({
      source: sourceTour2016,
      style: styleFunction
  map.addLayer(layerTour2016); // geojson laag toevoegen aan map

But how is it possible to have the features in an array? if i'm doing

features = [];

I receive an empty array...

1 Answer 1


you are trying to insert an array into an array, ol.source.Vector().getFeatures() already returns an array, now you could check if your source is ready and then get its features like this :

sourceTour2016.on('change', function(evt){
    var source=evt.target;
    if(source.getState() === 'ready'){
  • Perfect, thanks! Just if anyone else wants to use your code; you should add a ')' in the end
    – niels
    Jul 27, 2016 at 14:01

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.