Constantly update KmlLayer from file

08-12-2015 12:41 PM
New Contributor III

I have a simple code that gets a Kml String, writes it to a file, and then adds it to the kmlLayer. In the KML strings I receive, I have a placemark that updates the position of a vehicle. Is there a way to efficiently update that Kml object constantly, without having to remove the KmlLayer and add a new one. It doesn't have to be a fluid animation, I just want to see the placemark updating quickly. My current implementation looks like this:

public string AddKmlObject(KmlObject kmlObj, string folderPath, string oldObjectId)
        if (kmlObj != null)//ArcGis does not support KML Strings, so I write KML into a file
            System.IO.File.WriteAllText(_tempFilePath, kmlObj.ToKml());//Converts object to Kml Text
            KmlLayer kmlLayer = new KmlLayer(new Uri(_tempFilePath));
            kmlLayer.ID = kmlLayer.GetHashCode().ToString();

            if (oldObjectId != "")
                MySceneView.Scene.Layers.Remove(oldObjectId); //Remove previous Kml
            return kmlLayer.ID;

    return "";   

Is there a better way to do this?

0 Kudos
2 Replies
Esri Notable Contributor

Could you use a network link in your main kml with a refresh interval?. It will then pull the network link at the given interval.

0 Kudos
Occasional Contributor

I haven't tested any of these, but this could help you to avoid writing your kml data to disk and keep it in memory:

How to get uri for the resource dynamically created in memory

0 Kudos