Having recently started using OpenLayers, I find myself in a state of confusion. I'm attempting to retrieve all features from a kml vector layer, but have been unsuccessful thus far. It perplexes me as to what mistake I might be making.
Below is the code I am using:
var vector2 = new ol.layer.Vector({
source: new ol.source.Vector({
url: './energeticos.kml',
format: new ol.format.KML()
})
});
var features = vector2.getSource().getFeatures();
alert(features.length); //this alerts '0', even though there are more than 50 features!!
for (var i in features) {
var feature = features[i];
var featureName = feature.get('name');
$("#containerLeft").append('<li>' + featureName + '</li>');
}
The kml layer appears correctly on the map, and despite using the getFeatures function as shown in the code, no data is retrieved.
Any assistance provided will be highly valued.
P.S. I intend to take a short break and get some rest before returning to address this again in a few hours.