ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / Map Class / FindLayers Method
Name of the layer
(optional) When true the search continues in group layers. (default value = true)
Example

In This Topic
    FindLayers Method (Map)
    In This Topic
    Finds layers by name.
    Syntax
    Public Function FindLayers( _
       ByVal name As String, _
       Optional ByVal recursive As Boolean _
    ) As IReadOnlyList(Of Layer)

    Parameters

    name
    Name of the layer
    recursive
    (optional) When true the search continues in group layers. (default value = true)

    Return Value

    A read only list of Layers
    Example
    Find edit template by name on a layer
    // Finds and retrieves specific editing templates by name from layers in the active map.
    await QueuedTask.Run(() =>
    {
      var mainTemplate = activeMap.FindLayers("main").FirstOrDefault()?.GetTemplate("Distribution");
      var mhTemplate = activeMap.FindLayers("Manhole").FirstOrDefault()?.GetTemplate("Active");
    });
    Create Table Frame
    {
      //Create a table frame.
      await QueuedTask.Run(() =>
      {
    
      //Build 2D envelope geometry
      Coordinate2D rec_ll = new Coordinate2D(1.0, 3.5);
      Coordinate2D rec_ur = new Coordinate2D(7.5, 4.5);
      Envelope rec_env = EnvelopeBuilderEx.CreateEnvelope(rec_ll, rec_ur);
    
      //Reference map frame and layer
      MapFrame mf = layout.FindElement("Map Frame") as MapFrame;
      FeatureLayer lyr = mf.Map.FindLayers("GreatLakes").First() as FeatureLayer;
    
      //Build fields list
      var fields = new[] { "NAME", "Shape_Area", "Shape_Length" };
    
      //Construct the table frame
    
      var tableFrameInfo = new TableFrameInfo()
      {
        FieldNames = fields,
        MapFrameName = mf.Name,
        MapMemberUri = lyr.URI
      };
      var tabFrame = ElementFactory.Instance.CreateMapSurroundElement(
        layout, rec_env, tableFrameInfo) as TableFrame;
      });
    }
    Zoom map frame to extent of a single layer
    {
      //Zoom map frame to the extent of a single layer.
      await QueuedTask.Run(() =>
      {
        //Reference map and layer
        Map m = mapFrame.Map;
        FeatureLayer lyr = m.FindLayers("GreatLakes").First() as FeatureLayer;
    
        //Set the map frame extent to all features in the layer
        mapFrame.SetCamera(lyr, false);
      });
    }
    Change map frame extent to selected features in multiple layers
    {
      //Change the extent of a map frame to the selected features multiple layers.
      await QueuedTask.Run(() =>
      {
        //Reference MapFrame
    
        //Reference map, layers and create layer list
        Map m = mapFrame.Map;
        FeatureLayer fl_1 = m.FindLayers("GreatLakes").First() as FeatureLayer;
        FeatureLayer fl_2 = m.FindLayers("States_WithRegions").First() as FeatureLayer;
        var layers = new[] { fl_1, fl_2 };
        //IEnumerable<Layer> layers = m.Layers;  //This creates a list of ALL layers in map.
    
        //Set the map frame extent to the selected features in the list of layers
        mapFrame.SetCamera(layers, true);
      });
    }
    Change map frame extent to single feature with 15 percent buffer
    {
      //Change map frame extent to single feature with 10 percent buffer
      await QueuedTask.Run(() =>
      {
        //Reference the mapframe and its associated map
        Map m = mapFrame.Map;
    
        //Reference a feature layer and build a query (to return a single feature)
        FeatureLayer fl = m.FindLayers("GreatLakes").First() as FeatureLayer;
        QueryFilter qf = new QueryFilter();
        string whereClause = "NAME = 'Lake Erie'";
        qf.WhereClause = whereClause;
    
        //Zoom to the feature
        using (ArcGIS.Core.Data.RowCursor rowCursor = fl.Search(qf))
        {
          while (rowCursor.MoveNext())
          {
            //Get the shape from the row and set extent
            using (var feature = rowCursor.Current as ArcGIS.Core.Data.Feature)
            {
              Polygon polygon = feature.GetShape() as Polygon;
              Envelope env = polygon.Extent as Envelope;
              mapFrame.SetCamera(env);
    
              //Zoom out 15 percent
              Camera cam = mapFrame.Camera;
              cam.Scale = cam.Scale * 1.15;
              mapFrame.SetCamera(cam);
            }
          }
        }
      });
    }
    Find a layer
    {
      //Finds layers by name and returns a read only list of Layers
      IReadOnlyList<Layer> layers = map.FindLayers("cities", true);
    
      //Finds a layer using a URI.
      //The Layer URI you pass in helps you search for a specific layer in a map
      var lyrFindLayer = MapView.Active.Map.FindLayer("CIMPATH=map/u_s__states__generalized_.xml");
    
      //This returns a collection of layers of the "name" specified. You can use any Linq expression to query the collection.
      var lyrExists = MapView.Active.Map.GetLayersAsFlattenedList()
                         .OfType<FeatureLayer>().Any(f => f.Name == "U.S. States (Generalized)");
    }
    Retrieve a table from its container
    {
      var container = MapView.Active.Map;
    
      //the map standalone table collection
      var table = container.GetStandaloneTablesAsFlattenedList()
                              .FirstOrDefault(tbl => tbl.Name == "EarthquakeDamage");
    
      //or from a group layer
      var grp_layer = MapView.Active.Map.FindLayers("GroupLayer1").First() as GroupLayer;
      var table2 = grp_layer.FindStandaloneTables("EarthquakeDamage").First();
      //or         grp_layer.GetStandaloneTablesAsFlattenedList().First()
      //or         grp_layer.StandaloneTables.Where(...).First(), etc.
    
      //show the table in a table view
      //use FrameworkApplication.Current.Dispatcher.BeginInvoke if not on the UI thread
      FrameworkApplication.Panes.OpenTablePane(table2);
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also