NASA WorldWind Java includes a first-class KML/KMZ parser and renderer built on the same layer and renderable infrastructure used by all other WorldWind geometry. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nasaworldwind/worldwindjava/llms.txt
Use this file to discover all available pages before exploring further.
gov.nasa.worldwind.ogc.kml package maps every KML element — placemarks, overlays, folders, network links, and more — to Java objects that implement KMLRenderable. A separate gov.nasa.worldwind.ogc.collada package handles the COLLADA 3D model format referenced from KML <Model> elements. Together, these subsystems let you ingest standard geo-data formats without writing any custom parsing code.
Loading KML
The entry point for all KML/KMZ loading isKMLRoot.createAndParse(). It accepts a File, a URL, an InputStream, or a String path/URL, auto-detects whether the source is KML or KMZ, and returns a fully-parsed KMLRoot object.
Once parsed, wrap the KMLRoot in a KMLController — an adapter that bridges the KML object tree to WorldWind’s Renderable interface — and add the controller to a RenderableLayer:
LoadKMLFile.java
KMLViewer example application (gov.nasa.worldwindx.examples.kml.KMLViewer) adds a LayerTree and BalloonController on top of the basic loading pattern to give users a full feature-tree UI and click-to-open info balloons.
KML Structure
The KML object model mirrors the KML 2.2 specification. The key container and feature types are:| KML class | Description |
|---|---|
KMLDocument | Root-level container; may hold styles and nested features |
KMLFolder | Logical grouping of features |
KMLPlacemark | A named feature with associated geometry (KMLPoint, KMLLineString, KMLPolygon, or KMLMultiGeometry) |
KMLGroundOverlay | An image draped on the terrain within a LatLonBox |
KMLScreenOverlay | A 2D image overlay in screen space (logo, legend, compass rose) |
KMLNetworkLink | A link to another KML/KMZ document loaded dynamically |
KMLAbstractFeature and exposes getName(), getDescription(), getVisibility(), and getView() for camera positioning.
WorldWind maps each feature to one or more Renderable objects:
KMLPlacemarkwithKMLPointgeometry →PointPlacemarkKMLPlacemarkwithKMLLineString→PathKMLPlacemarkwithKMLPolygon→SurfacePolygonorExtrudedPolygonKMLGroundOverlay→SurfaceImageKMLModel→ COLLADA geometry node (see below)
KML Style
Styles in KML control the visual appearance of features. WorldWind parses all standard style elements:| KML class | Applied to |
|---|---|
KMLStyle | Inline or shared style definition |
KMLStyleMap | Maps normal/highlight states to KMLStyle instances |
KMLIconStyle | Icon image, scale, and color for KMLPlacemark points |
KMLLineStyle | Color and width for KMLLineString and polygon outlines |
KMLPolyStyle | Fill color and fill/outline flags for KMLPolygon |
KMLLabelStyle | Font color and scale for feature labels |
<styleUrl> are fetched from the KML document’s style table and applied to the corresponding renderables.
KML Network Links
KMLNetworkLink enables streaming and dynamically-updated KML by linking to an external document that can be refreshed on a timer or in response to camera changes. WorldWind’s retrieval service fetches network link documents asynchronously.
MonitorNetworkLinkRefresh.java
COLLADA Models
When aKMLPlacemark contains a <Model> element, WorldWind resolves the COLLADA model file referenced by the <href> inside the <Link> sub-element. The gov.nasa.worldwind.ogc.collada package provides a full COLLADA 1.4.1 parser that handles meshes, materials, textures, and hierarchical transforms.
The key classes in the COLLADA subsystem:
| Class | Description |
|---|---|
ColladaRoot | Top-level parsed COLLADA document; analogous to KMLRoot |
ColladaGeometry | A mesh geometry node |
ColladaEffect | Material/shader definition |
ColladaImage | Texture image reference |
ColladaAsset | Document metadata (unit, up-axis, etc.) |
KMLModel element triggers parsing of the linked .dae file automatically:
SampleKMLModel.kml
KMLRoot.createAndParse() as usual — WorldWind will automatically locate and render the COLLADA asset.
KML View Control
WorldWind providesKMLFlyViewController and KMLOrbitViewController to animate the camera to a KML <Camera> or <LookAt> view. Both extend the base KMLViewController:
AnimateToKMLView.java
KMLFlyViewController uses FlyToOrbitView animation (smooth flight to a <Camera> position), while KMLOrbitViewController uses BasicOrbitView animation (orbit/pan to a <LookAt> view).
Exporting KML
To serialize WorldWind shapes back to KML or KMZ, useKMLDocumentBuilder and KMZDocumentBuilder from the gov.nasa.worldwindx.examples.kml package. Both accept any Exportable object (including Path, SurfacePolygon, PointPlacemark, and ExtrudedPolygon):
ExportShapesToKML.java
Only shapes that implement
gov.nasa.worldwind.Exportable can be written to KML. All built-in WorldWind geometry types (Path, SurfacePolygon, SurfacePolyline, PointPlacemark, ExtrudedPolygon, etc.) implement Exportable. Custom renderables must implement the interface and handle the EXPORT_FORMAT_KML MIME type to participate in export.