This document is archived and information here might be outdated.  Recommended version.


IMap.AddLayers Method (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference (Carto)  

IMap.AddLayers Method

Adds multiple layers to the map, arranging them nicely if specified.

[Visual Basic .NET]
Public Sub AddLayers ( _
    ByVal Layers As IEnumLayer, _
    ByVal autoArrange As Boolean _
)
[C#]
public void AddLayers (
    IEnumLayer Layers,
    bool autoArrange
);
[C++]
HRESULT AddLayers(
  IEnumLayer* Layers,
  VARIANT_BOOL autoArrange
);
[C++]

Parameters Layers [in]
Layers is a parameter of type IEnumLayer autoArrange [in] autoArrange is a parameter of type VARIANT_BOOL

Product Availability

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

Remarks

The AddLayers method adds all of the layers in the IEnumLayer enumeration to the Map. Use the LayerCount property to get the total number of layers in the map. The autoArrange parameter controls the ordering of the layers.  If autoArrange is set to TRUE, the layers are added in the proper position as by their weight specified via ILayerPosition::LayerWeight.  By default, this means that the layers are sorted by layer type - Annotation layers on top, followed by Point geometry layers, Polyline geometry layers, and at the bottom Polygon geometry layers.  If autoArrange is true for this method, the position passed in is ignored as the position is determined by the auto arrange logic.
AddLayers automatically attempts to set the Map's SpatialReference property if a coordinate system has not yet been defined for the map.  When the SpatialReference property is set, the Map's MapUnits and DistanceUnits properties are additionally set.  AddLayers also sets the spatial reference for each layer (ILayer::SpatialReference). 
If no layers have a spatial reference, AddLayer checks the extent of the first layer (ILayer::AreaOfInterest) and if it has coordinates that look like geographic coordinates (XMin >= -180 and XMax <= 180 and YMin >= -90 and YMax <= 90), ArcMap assumes the data is in decimal degrees and sets the MapUnits to esriDecimalDegrees and DistanceUnits to esriMiles.
The full extent is recalculated each time a layer added.

See Also

IMap Interface | IMap.LayerCount Property | IMap.AddLayer Method

.NET Related Topics

Converting labels to geodatabase annotation for a single layer | Converting labels to geodatabase annotation for an entire map