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) { try { 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(); IkenaSceneView.Scene.Layers.Add(kmlLayer); if (oldObjectId != "") MySceneView.Scene.Layers.Remove(oldObjectId); //Remove previous Kml return kmlLayer.ID; } } catch { } return ""; }
Is there a better way to do this?
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.
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