Decodes KML and KMZ files (strings, ArrayBuffers, and Blobs) into a KMLPlacemarkFeatures, KMLGroundOverlayFeatures. Other features are emitted from events:

A KMLCodec is typically used by a Store to decode strings into LuciadRIA KMLFeatures. Consult the class documentation of the Store class for more information.

Styles are resolved according to the KML specification, as long as they are defined in the original KML file. Externally referenced styles are not resolved.

Supported versions

The current version of LuciadRIA supports the KML 2.3 standard.

Limitations

  • This KML Codec will only decode the following features:
    • Placemarks and internal styles
    • Shared Styles
    • NetworkLinks (references to other KML files)
    • KMZ files that consist of a single zipped KML-file and image resources. KML files that reference packaged resources are not currently supported.
    • GroundOverlays
    • ScreenOverlays
  • Cross-Origin requests that do not contain an "Access-Control-Allow-Origin" header in the response can not be loaded.
  • Camera positions are not supported.
  • LOD regions are not supported.
  • Collada models are not supported.
  • PhotoOverlays are not supported.

NOTE: This codec only handles well-formed, serialized KML documents and does not handle extensions to the KML Specification.

const codec = new KMLCodec();
const nlHandle = codec.on(KMLNetworkLinkEvent, (networkLink: KMLNetworkLinkFeature) => {});
const cursor = codec.decode({ content: "<kml>...</kml>" });

Since

2020.1

Hierarchy (view full)

Implements

Constructors

Methods

Events

"KMLNetworkLink" event

  • on("KMLNetworkLink", callback: ((networkLink) => void), context?: any) : Handle
  • Registers a callback function for the "KMLNetworkLink" event to process KMLNetworkLinkFeatures. This event is fired by the cursor when it identifies a <NetworkLink> element in the document.

    Parameters

    • event: "KMLNetworkLink"

      Always set to "KMLNetworkLink" for this event type.

    • callback: ((networkLink) => void)

      The callback function to be executed when KMLNetworkLinkFeature objects are decoded by the KMLCodec.decode function.

    • Optional context: any

      The context in which the callback function should be invoked.

      "KMLNetworkLink"

    Returns Handle

"KMLTree" event

  • on("KMLTree", callback: ((rootArray) => void), context?: any) : Handle
  • Registers a callback function for the "KMLTree" event. The callback function receives an array of KMLFeatures. This event is fired when the cursor has finished processing, and contains all of the previously processed and emitted nodes from that cursor.

    Parameters

    • event: "KMLTree"

      Always set to "KMLTree" for this event type.

    • callback: ((rootArray) => void)

      The callback function to be executed when the KMLCodec.decode function is called.

    • Optional context: any

      The context in which the function should be invoked.

      "KMLTree"

    Returns Handle

"KMLGroundOverlay" event

  • on("KMLGroundOverlay", callback: ((groundOverlay) => void), context?: any) : Handle
  • Registers a callback function for the "KMLGroundOverlay" event, that allows a listener to process KMLGroundOverlayFeatures. This event is triggered by the cursor whenever it identifies a <GroundOverlay> element in the document.

    Parameters

    • event: "KMLGroundOverlay"

      Always set to "KMLGroundOverlay" for this event type.

    • callback: ((groundOverlay) => void)

      The callback function to be executed when the KMLCodec.decode function is called.

    • Optional context: any

      The context in which the function should be invoked.

      "KMLGroundOverlay"

    Returns Handle

"KMLScreenOverlay" event

  • on("KMLScreenOverlay", callback: ((screenOverlay) => void), context?: any) : Handle
  • Registers a callback function for the "KMLScreenOverlay" event, that allows a listener to process KMLScreenOverlayFeatures. This event is triggered by the cursor whenever it identifies a <ScreenOverlay> element in the document.

    Parameters

    • event: "KMLScreenOverlay"

      Always set to "KMLScreenOverlay" for this event type.

    • callback: ((screenOverlay) => void)

      The callback function to be executed when the KMLCodec.decode function is called.

    • Optional context: any

      The context in which the function should be invoked.

    Returns Handle

    a handle to the registered callback with a single function 'remove'. This function can be used to unregister the callback function.

    "KMLScreenOverlay"

    Since

    2021.0

"KMLFatalError" event

  • on("KMLFatalError", callback: ((errorMessage) => void), context?: any) : Handle
  • Registers a callback function for the "KMLFatalError" event, that allows a listener to process errors which cause the KMLCodec to abort operations.

    Parameters

    • event: "KMLFatalError"

      Always set to "KMLFatalError" for this event type.

    • callback: ((errorMessage) => void)

      The callback function to be executed when the KMLCodec encounters a fatal error.

        • (errorMessage): void
        • Parameters

          • errorMessage: string

          Returns void

    • Optional context: any

      The context in which the function should be invoked.

      "KMLFatalError"

    Returns Handle

    Since

    2021.0