简体   繁体   中英

How do I programmatically create kmltreeview folders and add placemarks in them?

Using the C# winforms-ge-plugin I am adding wi-fi hotspots to the ge globe and kmltreeview as the search protocol finds them. I would like to group them based on cities using GPS coordinates. The plan is to group each city as a folder but I am having trouble figuring out how to create folders in the kmltreeview.

Originally I tried this:

        var folder = kmlTreeView.CreateNode(FC.GEPluginCtrls.ApiType.KmlFolder);
        kmlTreeView.ParseKmlObject(folder);

but it didn't work.

I found some javascript based code on another forum but it isn't working either:

        var folder = ge1.createFolder("test");
        folder.getFeatures().setVisibility(true);
        folder.getFeatures().setOpen(true);

        var placemark = ge1.createPlacemark();
        folder.getFeatures().appendChild(placemark);

        ge1.getFeatures().appendChild(folder);

Thanks for any help you can offer! TC

The CreateNode method takes any KmlObject as its parameter but you are passing it an enumerator of one of the types in the api.

Simply create the folder, then parse it in.

var folder = ge1.createFolder("test");
kmlTreeView.ParseKmlObject(folder);

To explain, the KmlTreeView doesn't generate or create KmlFolders, or 'kml' anything else - it just displays a view of KmlObjects loaded into it as a nodes in a hierarchy.

A 'folder', the thing that you actually see in the treeview, is just a representation of a KmlContainer, such as as KmlFolder or KmlDocument.

Another way to use the KmlTreeView is to simply load any kmlObject you load into the plugin directly into it as well. This would usually be the same object that is returned from a call to the GEWebBeowser's FetchKml method. For example.

   // load the plugin
    geWebBrowser1.LoadEmbededPlugin();

    // when the plug-in has loaded
    geWebBrowser1.PluginReady += (o, e) =>
    {
        // load the kml from the local server
        kmlTreeView1.SetBrowserInstance(e.ApiObject);
        geWebBrowser1.FetchKml("http://foo/some.kml");
    };

    // when the kml has loaded
    geWebBrowser1.KmlLoaded += (o, e) =>
    {
        // add the kml to the plugin and tree-view 
        geWebBrowser1.ParseKmlObject(e.ApiObject);
        kmlTreeView1.ParseKmlObject(e.ApiObject);
    };

This way the tree-view will synchronise with the display in the plug-in - so double-clicking on nodes in the tree-view will fly you to their location, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM