Construct a KML document and save it as a KMZ file.

Use case
If you need to create and save data on the fly, you can use KML to create points, lines, and polygons by sketching on the map, customizing the style, and serializing them as KML nodes in a KML Document. Once complete, you can share the KML data with others that are using a KML reading application, such as ArcGIS Earth.
How to use the sample
Tap on the sketch button in the toolbar to add a new KML. Select a type of feature and choose its color or icon. Tap on the map to sketch the KML. Tap the sketch button and tap “Save Sketch” to complete the sketch. Tap the file export button in the toolbar to export the file. Tap the sketch button and the “Clear Saved Sketches” button to clear the current KML document.
How it works
- Create an
KMLDocument. - Create an
KMLDatasetusing theKMLDocument. - Create an
KMLLayerusing theKMLDatasetand add it to the map’soperationalLayersarray. - Create
GeometryusingGeometryEditor. - Project that
Geometryto WGS84 usingGeometryEngine.project(_:into:). - Create an
KMLGeometryobject using that projectedGeometry. - Create an
KMLPlacemarkusing theKMLGeometry. - Add the
KMLPlacemarkto theKMLDocument. - Set the
KMLStylefor theKMLPlacemark. - When finished with adding
KMLPlacemarknodes to theKMLDocument, save theKMLDocumentto a file using theKMLNode.save(to:)method.
Relevant API
- GeometryEditor
- GeometryEngine
- KMLDataset
- KMLDocument
- KMLGeometry
- KMLLayer
- KMLNode
- KMLPlacemark
- KMLStyle
Tags
Keyhole, KML, KMZ, OGC