I have a piece of code that updates a KML overlay often. Some times, at random, my application crashes after replacing the KML layer from my Scene. I do not get an error message, not does it let me debug it, so I suspect is somewhere in the ArcGis code. Is this the correct way to update a KML layer?
string id = objId + "Overlay";
System.IO.File.WriteAllText(_tempFilePath + @\ + id + ".kml", kmlString);
var sourceUri = new Uri(_tempFilePath + @\ + id + ".kml"); //I receive KML as a string, so I save as a file to get an URI
if (MySceneView.Scene.Layers[id] == null) //first time adding the layer
{
var kmlLayer = new KmlLayer(sourceUri);
kmlLayer.ID = id;
kmlLayer.Opacity = _alpha;
MySceneView.Scene.Layers.Add(kmlLayer);
return id;
}
else //Update the layer
{
for(int i = MySceneView.Scene.Layers.Count - 1; i >= 0; i--)//for each layer
{
if (MySceneView.Scene.Layers.ID == id) //find the matching ID
{
var kmlLayer = new KmlLayer(sourceUri);
kmlLayer.ID = id;
kmlLayer.Opacity = _alpha;
MySceneView.Scene.Layers = kmlLayer; //repalce the layer with the updated one
return id;
}
}
}
return "";