I am using OpenLayers Version: v3.13.0 and i am trying to export all fetaures in my layer. my code is as follows
var projection = ol.proj.get('EPSG:3857');
var format = new ol.format.KML({
'maxDepth': 10,
'extractStyles': true,
'internalProjection': projection,
'externalProjection': projection
});
var newfeatures = [];
var vectorSource = layer.getSource();
vectorSource.forEachFeature(function(feature) {
var clone = feature.clone();
clone.setId(feature.getId()); // clone does not set the id
clone.getGeometry().transform(projection, 'EPSG:4326');
newfeatures.push(clone);
});
//console.log(newfeatures);
var string = new ol.format.KML().writeFeatures(newfeatures);
//console.log(string);
I am getting error "Uncaught TypeError: Cannot read property 'length' of undefined"
When i console the variable newfeatures I am getting all drawn features in an array. Please help me in resolving this