How to create folders when exporting OL to KML

المشرف العام

Administrator
طاقم الإدارة
I have this function that export all plotted features on my OpenLayers (2.6) map, by using the OpenLayers.Format.KML as follows:

var featuresToExport = [];for (var i = 0; i < MAP.__layers.length; i++) { if (MAP.__layers.getVisibility() && MAP.__layers.features != null) { for(var j = 0; j < MAP.__layers.features.length; j++){ featuresToExport.push(MAP.__layers.features[j]); } }}var format = new OpenLayers.Format.KML({ 'maxDepth':10, 'extractStyles': true, 'extractAttributes': true, 'extractTracks': false, 'internalProjection': MAP.__map.baseLayer.projection, 'externalProjection': new OpenLayers.Projection("EPSG:4326")});var kml = format.write(featuresToExport);That way, all features are put at the same level on the KML. I would like to be able to arrange them in folders, for example for each layer.

How can I do that? The write function always write the complete KML structure, otherwise I could do something like this:

for (var i = 0; i < MAP.__layers.length; i++) { if (MAP.__layers.getVisibility() && MAP.__layers.features != null) { featuresToExport = []; kml += "Layer " + i + ""; for(var j = 0; j < MAP.__layers.features.length; j++){ featuresToExport.push(MAP.__layers.features[j]); } // write this features kml += format.write(featuresToExport); kml += ""; }}

أكثر...
 
أعلى