Repetitive add and remove of KMLLayers

2396
0
10-07-2015 03:11 AM
AleksandraStojnev2
New Contributor

I got an assigment to add photo overlay on ArcGis Scene. Photo is updated after few seconds.

I couldn't find another solution, so I use KMLLayer, in following scenario:

  1-create temporary kml file with ground overlay object

  2-create KMLLayer with file uri

  3-add new layer to scene

  4-remove old one

First 3 steps are working smoothly, but when I try to remove old layer, application sometimes crashes (I can reproduce crashing with zooming and panning scene)

Code is bellow.

  private async void AddKMLLayer(string kml, string id, string oldid)

  {

       await AddLayer(kml, id, SearchCompleted, oldid);

  }

  private async Task AddLayer(string kml, string id, Action<KmlLayer> callback, string oldid)

  {

       Uri sourceUri = new Uri(Environment.GetFolderPath(_folder + @"\" + id + ".kml");

       KmlLayer layer = new KmlLayer(sourceUri);

       layer.ID = id;

       _arcGISmapWPF.SceneView.IsEnabled = false;

       await layer.InitializeAsync();

       callback(layer, oldid);//add layer when initialized

  }

  private void SearchCompleted(KmlLayer layer, string oldid)

  {

       _arcGISmapWPF.SceneView.Scene.Layers.Add(layer);          

       _arcGISmapWPF.SceneView.Scene.Layers.remove(oldid);

  }

Tags (2)
0 Kudos
0 Replies