KML from Cesium

Hi,

There is a way to generate a KML of a promise correctly loaded in Cesium?

For example i have loaded Italy.kml with his polygones’s coordinates and styles. I want to generate a kml file with my customisation.

Any suggestion?

Thanks,

Gianmaria

Hello Gianmaria,

This functionality is not currently included in Cesium, but let me know if you are interested in implementing it!

Best,

Hannah

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)

Hello Giammaria,

I found that in your Italy.kml is missing the <kml> starting tag, at the second line of the file.

This is the complete line tag:

<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">

A presto

Roberto

Hello Roberto,

i don’t know if this tag is necessary for properly display the kml. If you try to load it on cesium i don’t think there are display problems.

Well, it is needed if you load it inside QuantumGIS or other programs that use GDAL/OGR library.

Normally, for each xml tag, a start and end <> </> are needed. In your kml only exists an end </kml> without a start <kml>.

GoogleEarth does not report this as an error (but it is only a "warning").

So, I suggest you to insert it.

A presto

Roberto

I checked, there isn’t an end tag as . Maybe i don’t understand what you mean. Anyway do you suggest to replace xml tag on first line with your kml tag or only insert it on the second line?

I checked, there isn’t an end tag as

Maybe i don’t understand what you mean. Anyway do you suggest to replace xml tag on first line with your kml tag or only insert it on the second line?

BTW, simply try to save a KML from GoogleEarth (also re-saving your from GE) and see what it will contains.

That is the correct syntax.

:slight_smile:

A presto

Roberto