ArcObjects Library Reference (Carto)  

IMap.Layers Property

The layers in the map of the type specified in the uid. If recursive is true it will return layers in group layers.

[Visual Basic .NET]
Public Function get_Layers ( _
    [ByVal uid As UID], _
    [ByVal recursive As Boolean] _
) As IEnumLayer
[C#]
public IEnumLayer get_Layers (
    UID uid,
    bool recursive
);
[C#]

Optional Values

uid   Supply 0 as a default value.
recursive   Supply true as a default value.
[C++]
HRESULT get_Layers(
  IUID* uid,
  VARIANT_BOOL recursive,
  IEnumLayer** Layers
);
[C++]

Parameters

uid [in, optional, defaultvalue(0)]

  uid is a parameter of type IUID

recursive [in, optional, defaultvalue(VARIANT_TRUE)]   recursive is a parameter of type VARIANT_BOOL Layers [out, retval]

  Layers is a parameter of type IEnumLayer

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Description

UID specifies the interface identifier (GUID) that represents the type of layer you want returned.

recursive Use True to also return the layers inside group layers.

See the sample code associated with the FeatureSelection property for an example of use.

Remarks

The Layers property returns an IEnumLayer which consists of only those layers with the type specified by the input interface unique indentifier. The Layer property provides access to all of the Layers in a map; using the Layers property however, you can access just the layers of a particular type. For example, use this property to get a collection of FeatureLayers only. To create this collection use IGeoFeatureLayer's GUID as the FeatureLayer object is the only type of layer that implements this interface. Similarly, to get just a collection of the graphics layers, pass the IGraphicsLayer's GUID. Use IDataLayer if you want all the layers that have data in them, this would not include GroupLayers for example. Layers that implement IDataLayer include FeatureLayers, FDOGraphicsLayers (Annotation), TinLayer, RasterLayer, and CoverageAnnotationLayer.
Here are the GUIDs for some of the common intefaces searched for:
{6CA416B1-E160-11D2-9F4E-00C04F6BC78E} IDataLayer
{40A9E885-5533-11d0-98BE-00805F7CED21} IFeatureLayer
{E156D7E5-22AF-11D3-9F99-00C04F6BC78E} IGeoFeatureLayer
{34B2EF81-F4AC-11D1-A245-080009B6F22B} IGraphicsLayer
{5CEAE408-4C0A-437F-9DB3-054D83919850} IFDOGraphicsLayer
{0C22A4C7-DAFD-11D2-9F46-00C04F6BC78E} ICoverageAnnotationLayer
{EDAD6644-1810-11D1-86AE-0000F8751720} IGroupLayer
[C++]

See Also

IMap Interface

.NET Snippets

Loop Through Layers of Specific UID |

.NET Samples

Create a custom selection extension by extending ArcObjects (Code Files: SelectionExtension) | Custom selection extension (Code Files: SelectionExtension) | Graphics layers ToolControl (Code Files: GraphicsLayersListCtrl) | Multivariate renderer (Code Files: PropPageForm) | Schematic diagram auto refresh (Code Files: FormAutorefresh) | Subset network evaluators (Code Files: SubsetHelperUI) | Using the traversal result to select source features (Code Files: SelectFeaturesTool) |

.NET Related Topics

Add-in coding patterns | How to access maps and layers via the MapDocument | Utility COM objects |