Hello.
I added export tool in the draw widget, at client side.
Because my maps aren't in WGS84, I needed to use 'esri/geometry/projection'.
It's perhaps not so optimal if there are very much graphics, but in my case the drawings done with Draw widget are not so many.
So I'm looping in this._graphicsLayer.graphics and I construct the KML as a string, based on the specification and analyzing ...geometry.geoType in order to create Point, LineString or Polygon objects.
Example:
kmlContent = kmlContent
+ " <name>" + graphics.attributes.OBJECTID + "</name>\r\n"
+ " <styleUrl>#drawing" + (i + 1) + "</styleUrl>\r\n";
for (var j = 0; j < geometry.paths.length; j++) {
kmlContent = kmlContent
+ " <LineString>\r\n"
+ " <altitudeMode>clampToGround</altitudeMode>\r\n"
+ " <coordinates>\r\n";
for (var k = 1; k < geometry.paths.length; k++) {
var projPt1 = new Point({ x: geometry.paths[k-1][0], y: geometry.paths[k-1][1], spatialReference: mySpatialReference });
var projPt2 = new Point({ x: geometry.paths[0], y: geometry.paths[1], spatialReference: mySpatialReference });
var geoPt1 = projection.project(projPt1, wgsSpatialReference);
var geoPt2 = projection.project(projPt2, wgsSpatialReference);
kmlContent = kmlContent + " " + geoPt1.x + "," + geoPt1.y + ",0 "
+ geoPt2.x + "," + geoPt2.y + ",0\r\n";
}
kmlContent = kmlContent
+ " </coordinates>\r\n"
+ " </LineString>\r\n";
}
geometry is this._graphicsLayer.graphics.geometry;
At the end I use the download function that exists in CSVUtils:
return CSVUtils._download(filename, kmlContent);