Load all layers

423
2
Jump to solution
03-31-2022 05:18 AM
DavidMrázek
Occasional Contributor II

Good day,
is there any way to load all the layers in which an element is selected? I would like to load them into the list?
All I found was that I loaded only the first layer or the layer I searched for by name.
I will be happy for any advice.

Thank you
David

0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor
QueuedTask.Run(() => {
  var graphics_layers = MapView.Active.Map.GetLayersAsFlattenedList()
                         .OfType<GraphicsLayer>().ToList();
 var graphics_layer_with_sel = graphics_layers
           .Where(gl => gl.GetSelectedElements().Count > 0).ToList();

 var feat_layers = MapView.Active.Map.GetLayersAsFlattenedList()
                             .OfType<BasicFeatureLayer>().ToList();
 var feat_layer_with_sel = feat_layers
         .Where(fl => fl.GetSelection().GetCount() > 0).ToList();

View solution in original post

2 Replies
CharlesMacleod
Esri Regular Contributor
QueuedTask.Run(() => {
  var graphics_layers = MapView.Active.Map.GetLayersAsFlattenedList()
                         .OfType<GraphicsLayer>().ToList();
 var graphics_layer_with_sel = graphics_layers
           .Where(gl => gl.GetSelectedElements().Count > 0).ToList();

 var feat_layers = MapView.Active.Map.GetLayersAsFlattenedList()
                             .OfType<BasicFeatureLayer>().ToList();
 var feat_layer_with_sel = feat_layers
         .Where(fl => fl.GetSelection().GetCount() > 0).ToList();
DavidMrázek
Occasional Contributor II

That's exactly it, thank you very much!!!

0 Kudos