This document is archived and information here might be outdated. Recommended version. |
ArcObjects namespaces > Controls > ESRI ArcGIS Controls > Interfaces > IM > IMapControlDefault Interface > IMapControlDefault.Layer Property (ArcObjects .NET 10.4 SDK) |
Layer at the supplied index.
[Visual Basic .NET] Public Function get_Layer ( _ ByVal index As Integer _ ) As ILayer
[C#] public ILayer get_Layer ( int index );
[C++]
HRESULT get_Layer(
long index,
ILayer** pLayer
);
[C++]
Parameters index [in] index is a parameter of type long pLayer [out, retval]
pLayer is a parameter of type ILayer
The Layer property is a shortcut to IMap::Layer and is used to access a particular layer in the Map. The Layer at the beginning or top of the collection with an index of 0 will be drawn last, whilst the Layer at the bottom of the collection will be drawn first.
To loop through a Map's Layer collection use the Layer property in conjunction with the LayerCount property.
In C# use the get_Layer method, as indexed property accessors are not supported.
ILayer layer;
//First layer to draw
layer=(ILayer2) axMapControl1.get_Layer(0);
//Second layer to draw
layer=(ILayer2) axMapControl1.get_Layer(1);
//Last layer to draw
layer=(ILayer2) axMapControl1.get_Layer(axMapControl1.LayerCount - 1);
//Loop through a map's layer collection
ILayer layer;
for (int i=0; i<=axMapControl1.LayerCount-1; i++)
{
layer=(ILayer) axMapControl1.get_Layer(i);
System.Windows.Forms.MessageBox.Show(layer.Name);
//Do something...
}
The IMapControlDefault, (and higher numbered IMapControl interfaces) and IMapControlDefault interfaces have a default indexed property called Layer. The Controls interop assembly which provides access to these interfaces have the default Layer property. However, if you are working directly with the AxControls class use the get_Layer method.
Dim pLayer As ILayer
'First layer to draw
pLayer=AxMapControl1.get_Layer(0)
'Second layer to draw
pLayer=AxMapControl1.get_Layer(1)
'Last layer to draw
pLayer=AxMapControl1.get_Layer(AxMapControl1.LayerCount - 1)
'Loop through a map's layer collection
Dim i As Long
Dim pLayer As ILayer
For i=0 To AxMapControl1.LayerCount - 1
pLayer=AxMapControl1.get_Layer(i)
'Do something...
Next i
IMapControlDefault Interface | IMapControl4.ClearLayers Method | IMapControlDefault.ClearLayers Method | IMapControl3.ClearLayers Method | IMapControl4.DeleteLayer Method | IMapControlDefault.DeleteLayer Method | IMapControl3.DeleteLayer Method | IMapControl4.LayerCount Property | IMapControl3.LayerCount Property | IMapControlDefault.LayerCount Property | IMapControlDefault.MoveLayerTo Method | IMapControl4.MoveLayerTo Method | IMapControl3.MoveLayerTo Method