Accessing maps and layers via the MapDocument
In the following code example, the names of these objects are reported to the console. Do the following steps to access maps and layers:
- Create a MapDocument.
IMapDocument pMapDocument = new MapDocumentClass();
[VB.NET]
Dim pMapDocument As IMapDocument = New MapDocumentClass()
- Enumerate the maps in the MapDocument and print their names to the console. See the following code example:
if (pMapDocument.get_IsMapDocument(path))
{
pMapDocument.Open(path, null);
IMap pMap;
for (int i = 0; i <= pMapDocument.MapCount - 1; i++)
{
pMap = pMapDocument.get_Map(i);
Console.WriteLine(pMap.Name);
IEnumLayer pEnumLayer = pMap.get_Layers(null, true);
pEnumLayer.Reset();
ILayer pLayer = pEnumLayer.Next();
while (pLayer != null)
{
Console.WriteLine(pLayer.Name);
pLayer = pEnumLayer.Next();
}
}
}
[VB.NET]
If pMapDocument.IsMapDocument(Path) Then
pMapDocument.Open(Path, Nothing)
Dim pMap As IMap
Dim i As Integer
For i = 0 To pMapDocument.MapCount - 1 Step i + 1
pMap = pMapDocument.Map(i)
Console.WriteLine(pMap.Name)
Dim pEnumLayer As IEnumLayer = pMap.Layers(Nothing, True)
pEnumLayer.Reset()
Dim pLayer As ILayer = pEnumLayer.Next()
While Not pLayer Is Nothing
Console.WriteLine(pLayer.Name)
pLayer = pEnumLayer.Next()
End While
Next
End If
Development licensing | Deployment licensing |
---|---|
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime |