Search code examples
c#treeviewgoogle-earth-plugin

Using GE Plugin, how do I programmatically put placemarks in folders?


Sorry for the incessant questions but I just can't seem to get the hang of this API.

This would seem to be a very simple operation but I haven't been able to figure it out.

I create a folder in the PluginReady() callback:

    folder = ge1.createFolder("Sites");
    folder.setName("Sites");
    kmlTreeView1.ParseKmlObject(folder);

With the folder created I wait for data to come in that will create a placemark that goes in this folder. When that data arrives I create a placemark and then attempt to put it into the kmltreeview 'Sites' folder:

    //kmlTreeView1.ParseKmlObject(placemark);
    KmlTreeViewNode node = kmlTreeView1.GetNodeById("Sites");
    node.ApiObject.getFeatures().appendChild(placemark);
    ge1.getFeatures().appendChild(node.ApiObject);

I believe the placemark is in the folder because when I double click the folder a balloon pops up pointing to the placemark. However, the folder does not have a plus sign to indicate there is something in it. The kmltreeview1 property "ShowPlusMinus" is set to true.

If someone can point me in the right direction I would appreciate it.


Solution

  • The KmlTreeView doesn't create any kml at all ever...if you load a empty KmlFolder into the tree then it is an empty kmlFolder. If you then do something with the KmlFolder it is not going to change what is in the tree.

    For example, if you add features to that same KmlFolder after you have create a treenode from it they will not be shown in the treeview - because you haven't added them to the treeview, you have added them to the KmlFolder.

    In your example, you would have to remove the empty sites node from the tree. Then create a new node based on the folder that has some contents and then add that back to the tree.

    KmlTreeViewNode node = kmlTreeView1.GetNodeById("Sites"); // get the empty node you added to the tree
    node.ApiObject.getFeatures().appendChild(placemark); // get the KmlFolder and add a placemark
    ge1.getFeatures().appendChild(node.ApiObject); // add the KmlFolder and features to the plugin
    kmlTreeView1.Nodes.RemoveByKey("sites"); // remove the empty node from the tree...
    kmlTreeView1.ParseKmlObject(node.ApiObject); // add the KmlFolder that contains your placemark
    

    On a side note - the KmlTreeView is essentially designed to load KML files into it, and to sync with the plugin. Whilst you can create individual tree nodes like this it isn't how it was designed to be used...