Export graphics to KML/KMZ

7030
5
04-09-2015 08:47 AM
GeorgeOulton1
New Contributor III

Hello All

Has anyone tried exporting graphics created in the drawing widget for WAB 1.1 to KMZ or KML?

Should this happen server-side or is it possible within the javascript?

Any feedback would be wonderful!

Thanks

George

5 Replies
OwenEarley
Occasional Contributor III

You could do this client side you would just need to write a javascript function that converts the graphics into KML. Check out the KML Documentation Introduction

You would need to convert the ESRI graphic geometry object into the equivalent KML geometry:

  • ESRI Point - KML Point
  • ESRI Polyline (path) - KML LineString
  • ESRI Polygon - KML Polygon
0 Kudos
GeorgeOulton1
New Contributor III

Thanks for the reply Owen

I was hoping to have it run along those lines, but my point of confusion is around the drawbox dijit. It seems all the graphics are added there and not to a graphics layer and I'm not too sure on how the drawbox works, is it like a graphics layer?.

UPDATE:

I see, I can inherit the map and get the current graphics layer from the map and then work from there.

Thanks

0 Kudos
JeremieCornet1
Occasional Contributor II

Hi George,

The drawBox dijit use a graphic layer.

You can access the graphicLayer in the draw widget with :

this.drawBox.drawLayer

Maybe you could add your kmz export functionnality to the non-official eDraw widget

magis-nc/esri-webappbuilder-widget-eDraw · GitHub

This widget has allready a "json export/import" functionnality.

TylerArmstrong
New Contributor

I know this is a very old post, but did anybody have success adding kml/kmz export functionality to the draw (or eDraw) widget? 

0 Kudos
GeoguichetGeoguichet
New Contributor III

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);

0 Kudos