Hi Steve, Nick, everyone!
Using ArcGis Javascript Api 3.22 I create a web map viewer.
I take one (only none -- see red circle above!) client side graphic in the variable named selected
I can get the Json of selected using:
Using Terraformer I can transform from ArcGis Json to GeoJson using:
currentPrimitive = Terraformer.ArcGIS.parse(selected.toJson());
but in currentPrimitive the coordinates look like 0.000000111 .. a lot of 0000...(terraformer coordinates transformations??)
If I want to see geographic coordinates in GeoJson I need to use the next line instead:
currentPrimitive = Terraformer.ArcGIS.parse(selected.toJson()).toMercator();
Now I am ready to export to KML using JSON to KML, but before I had to fix some issues:
1) Inside geoJsonString I found some null that I had to replace with {}
2) I had to complete the geoJsonString using the strings 'inicio' and 'fin' (to configure a geoJson FeatureCollection with the selected graphic -- a featurecollection with only one graphic)
geoJsonString = JSON.stringify(currentPrimitive);
inicio="{\"type\":\"FeatureCollection\",\"properties\":{},\"features\":[ ";
fin= " ]}";
geoJsonString2 = geoJsonString.replace("null", "{}");
geoJsonString3 = inicio + geoJsonString2 + fin;
var kml = tokml(JSON.parse(geoJsonString3));
and now I am ready to put the KML in a HTML element using an hyperlink:
kmlString2 = encodeURIComponent(kml);
d = document.getElementById('download-kml');
d.setAttribute('href', `data:text/kml;charset=utf-8,${kmlString2}`);
d.setAttribute('Descargar', 'graphics.kml');
And the graphic border inside google earth:
Thanks for your suggestions.
But now I need to export the KML with the ArcGis Api symbols and colors. Do you have ideas to deal with it?
Thank you!
Alexys H Rodríguez