Select to view content in your preferred language

Delete layers saved in memory database from Active map on Pro closing

1441
10
07-27-2023 01:41 AM
ShaneTsh
Emerging Contributor

 

Hi,

I have created a group layer containing multiple layers inside it in the memory database. But what I need is to delete group layer as well as sub layers inside it when application is closed. Because if these layers are not deleted and since memory database will be deleted on close after opening the project again these layers are shown in red exclamation mark.

I thought of deleting the layers in the UninitializeAsync method of the dockpane by fetching the group layer from the active map.

var groupLayers = MapView.Active?.Map?.Layers?.OfType<GroupLayer>();

But it looks like Active map becomes null when it reaches to the UninitializeAsync  of the dock pane.

Using other approach I implemented this when the project is opened again using MapViewInitializedEvent or DrawCompleteEvent and not on close.

void OnMapViewInitialized(MapViewEventArgs args)
{
     var mapView = args?.MapView;
     if (mapView is null)
          return;
 
     QueuedTask.Run(() =>
     {
          var groupLayers = mapView.Map.Layers?.OfType<GroupLayer>().ToList();
          foreach (var groupLayer in groupLayers.Where(groupLayer => groupLayer.Name.StartsWith("MyLayer")))
               mapView.Map.RemoveLayer(groupLayer);
     });
}
 

Not sure if any other better way like deleting on close only which I cant achieve right now.

@Wolf @GKmieliauskas @CharlesMacleod 

Tags (1)
0 Kudos
10 Replies
ShaneTsh
Emerging Contributor

@Wolf  But I dont want to create that table just when the project is opened. I am creating the table only when my functionality is being used.

0 Kudos