This is what I produced. Very basic but functional.
I have used XMLWriter-1.0.0-min.js library (see attached).
kmlGenerator.js is my code that is called from this function:
function generateKml(){
if (selectedEntity.parent._children.length == 1)
kmlGenerator(selectedEntity, false);
else
kmlGenerator(selectedEntity.parent, true);
}
``
selectedEntity is a global value created after double click on the country loaded on cesium(italy or afghanistan for example).
This function serves to understand if the entity is multigeometry(italy) or not(afghanistan).
Of course, this script will only work with this format of kml. For other format it’s necessary change something.
At now this function on the kmlGenerator.js works only on chrome:
function download(filename, text) {
var elem = document.createElement(‘a’);
elem.setAttribute(‘href’, ‘data:text/plain;charset=utf-8,’ + encodeURIComponent(text));
elem.setAttribute(‘download’, filename);
elem.click();
}
``
Italy.kml (41.3 KB)
Afghanistan.kml (26.9 KB)
XMLWriter-1.0.0-min.js (2.43 KB)
kmlGenerator.js (4.28 KB)