我正在使用OpenLayers版本:v3.13.0,我試圖導出我的圖層中的所有fetaures。我的代碼如下Openlayers 3 KML導出writeFeatures()不起作用
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);
我收到錯誤 「遺漏的類型錯誤:未定義無法讀取屬性‘長’」
當我安慰變量newfeatures我得到的所有在數組中繪製特徵。請幫助我解決這個問題
我修改writeFeatures(newfeatures); writeFeatures(newfeatures [0]);然後錯誤消失,但功能不會轉換爲xml輸出,如下所示 –
user2399505