Click or drag to resize

KML

Insight3D supports loading and rendering.kml and .kmz documents in a 3D scene. A simple tree of the document and its content is available using the KmlDocument, KmlFeature, KmlContainer, KmlFolder, and KmlNetworkLink types.

Basics

Insight3D provides a simple KML object model that can be used to access information about KML features and modify properties associated with KML rendering. KmlGraphics, accessed from the CentralBodyGraphicsKml property, contains methods for loading, unloading, and managing KML documents. The following code sample loads a KML document from a Uri asynchronously. Synchronous load methods are also provided and described below.

C#
Scene.CentralBodies.Earth.Kml.DocumentLoaded += OnDocumentLoaded;
Scene.CentralBodies.Earth.Kml.LoadDocumentAsync(kmlPath);
C#
private void OnDocumentLoaded(object sender, KmlDocumentLoadedEventArgs e)
{
    KmlDocument document = e.Document;
    string documentName = document.Name;
}
Loading KML

The DocumentLoaded event is raised when the KML document has completed loading. The KmlDocumentLoadedEventArgs contain the KmlDocument that was loaded, as shown in the code sample above. Since KmlDocument derives from KmlFeature and KmlFeature, you can then access various properties of the document, including its Children. The following image illustrates the KML class hierarchy:

KML Class Hierarchy
Documents

As shown above, documents can be loaded from .kml and .kmz files. They can also be loaded directly from a string, if that string contains valid KML content. The following code sample loads a KML document synchronously from a string:

C#
string kmlContent =
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
    "<kml xmlns=\"http://www.opengis.net/kml/2.2\">" +
    "<Placemark>" +
    "<name>AGI</name>" +
    "<Point><coordinates>-75.59672941368964,40.03876371991856</coordinates></Point>" +
    "</Placemark>" +
    "</kml>";
KmlDocument kmlDocument = Scene.CentralBodies.Earth.Kml.Load(kmlContent);

You can enumerate through the documents that were loaded by using the KmlGraphicsDocuments collection. To unload a document, call the Unload method. Similarly, you can unload all documents from the scene by calling UnloadAll.

C#
KmlDocument document = Scene.CentralBodies.Earth.Kml.LoadDocument(kmlPath);
Scene.CentralBodies.Earth.Kml.Unload(document);
Scene.CentralBodies.Earth.Kml.UnloadAll();
Note Note

Every KmlFeature, including KmlDocument, has an IsLoaded property that indicates whether the object is currently loaded or not. Once a KmlDocument has been unloaded, it is no longer valid, and accessing methods and properties on the document or associated features will throw an exception indicating such.

Features

KmlFeature is the primary type for KML in Insight3D. It provides basic properties such as Display, querying feature attributes, and allows you to fly to or show the balloon associated with the feature. You can also get the actual KML content of the KmlFeature. The following code sample queries various attributes of the feature, and then flies to the feature:

C#
KmlDocument kmlDocument = Scene.CentralBodies.Earth.Kml.LoadDocument(kmlPath);
KmlFeature kmlFeature = kmlDocument.Children[0];
Console.WriteLine(kmlFeature.Name);
Console.WriteLine(kmlFeature.Description);
Console.WriteLine(kmlFeature.Snippet);
Console.WriteLine(kmlFeature.Content);

kmlFeature.FlyTo();
Scene.Render();
KML Feature
Note Note

KML documents may specify the height of a feature using absolute altitude mode, which is measured relative to mean sea level (MSL). In order to compute this height, Insight3D requires that the EarthCentralBodyMeanSeaLevel property be configured, or it will throw an exception. See the Terrain topic for more information on obtaining and loading MSL data into DME Component Libraries.

Network Links

A KmlNetworkLink will update automatically in the scene. Like KmlFeature, which it derives from, you can query and set various network link related properties. The following code changes the RefreshMode and RefreshInterval of the network link:

C#
KmlDocument kmlDocument = Scene.CentralBodies.Earth.Kml.LoadDocument(kmlPath);
KmlNetworkLink networkLink = (KmlNetworkLink)kmlDocument.Children[0];

networkLink.RefreshMode = KmlNetworkLinkRefreshMode.OnInterval;
networkLink.RefreshInterval = Duration.FromSeconds(5);
Folders and Containers

KmlContainer shares all the same attributes and behavior of KmlFeature, but also contains other KmlFeatures. Both KmlFolder and KmlDocument derive from KmlContainer. When the Display property is set on a KmlContainer, all contained features will also show or hide. The following example enumerates through the children and then toggles off the display of a KmlFolder:

C#
KmlContainer folder = (KmlContainer)kmlDocument.Children[0];
foreach (KmlFeature feature in folder.Children)
{
    Console.WriteLine(feature.Name);
}

folder.Display = false;
Picking

Picking allows users to select and interact with KML features on the screen. The Pick(Int32, Int32) method returns information about KmlFeatures, along with other Primitives. The below example demonstrates picking on a KmlFeature:

C#
Collection<PickResult> collection = Scene.Pick(x, y);

if (collection.Count == 1)
{
    KmlFeature feature = (KmlFeature)collection[0].Objects[0];

    if (feature != null)
    {
        // Just a KmlFeature was picked, fly to it
        feature.FlyTo();
    }
}
Picking KML
Compatibility

Insight3D supports almost the entire KML specification and many extensions, but still lacks support for certain features. The following KML-related features are not currently supported in Insight3D:

  • The tessellate option (Lines on Terrain) on LineString and LinearRing features

  • Globe overlays drawn at an altitude Fade extent for regions

  • Photo overlays

  • Highlighted style

  • Updating of models with link refresh properties

  • Anything in the Google extension namespace

  • Updating screen and globe overlays with link refresh properties