views:

810

answers:

2

I build a winforms app in C# which embeds Google Earth as a viewer. Like this. My app receives data regularly, transforms that to KML, and displays the result in Google Earth. Whenever I receive the new update, I want to delete the old KML, but I could not find how in GE API. All I found is making the old stuff invisible:

        this.ge = new ApplicationGEClass();
        // ....
        string newKml = this.ConvertNewInputToKML();
        this.ge.LoadKmlData(ref newKml);
        FeatureGE oldFeature = this.ge.GetFeatureByName("myOldKmlFeature");
        oldFeature.Visibility = 0;

I wonder if this will cause memory/performance issue on the long run. Or is there a way to delete from Google Earth KML nodes?

+1  A: 

You can use a NetworkLink with a time based refresh to replace old data at a certain interval. http://code.google.com/apis/kml/documentation/kmlreference.html#networklink

There might be other ways of specifying it from within KML as well.

Ben Hughes
Networklink assumes that there is a REST service out emitting KML. I do not have that neither I want to build one as it makes deployment more complicated than necessary. I want everything inside my own executable.
"A URL (either an HTTP address or a *local file* specification). When the parent of <Link> is a NetworkLink, <href> is a KML file." -- http://code.google.com/apis/kml/documentation/kmlreference.html#link. There is probably a simpler way, but I do think this will work without complicating deployment.
Ben Hughes
Yes it does. COM calls of GE like "LoadKmlData" method allows to push KML in without complicating deployment. I just wonder how can I remove the old stuff via similar COM calls.
A: 

KML is nothing but XML. I would recommend that you delete the appropriate nodes from the XML tree and re-write to file every so often.

I don't know KML that well yet. Do you need to re-load the entire file every time you want to make changes to what has been rendered?

San Jacinto
According to my understanding, if you submit the same KML file 2x using the "this.ge.LoadKmlData(ref newKml);" method, you will have two copies loaded in the model tree. They do not overwrite one another.