Select to view content in your preferred language

How I can gen layer by name?

3900
8
03-09-2011 02:31 AM
AnatoliiTerentiev
Deactivated User
c#+.net+arcgis Engine
I can gen layet by index?, for example - MapControl1.get_Layer(8)
Can't anybody say how I can get layer by name?
Thanks for any help or reference!
0 Kudos
8 Replies
JanBurdziej1
Emerging Contributor
You can loop through all layers and check names.

Example in vb.net:

        ' Enumerate layers
        pEnumLayers = pMap.Layers
        pEnumLayers.Reset()
        pLayer = pEnumLayers.Next()

        Do Until pLayer Is Nothing
                      If pFLayer.Name = [layer name] Then
                        Exit Do
                    End If
            pLayer = pEnumLayers.Next
        Loop


Regards,
Jan
0 Kudos
AnatoliiTerentiev
Deactivated User
Thank you very much!
0 Kudos
AnatoliiTerentiev
Deactivated User
But if there are some composite layer?
0 Kudos
AlexanderGray
Honored Contributor
The imap.layers method has a recursive boolean argument as the second argument.  That looks into composite layers.
0 Kudos
MichaelRobb
Honored Contributor
You can check if its a group layer,  then cycle through the composite layers within that group.

example here:


 For j = 0 To pMap.LayerCount - 1
                        

                        GetName = pMap.Layer(j).Name 
                       
                        'One level in
                        If TypeOf pMap.Layer(j) Is ESRI.ArcGIS.Carto.IGroupLayer Then

                            pCompositeLayer = pMap.Layer(j)

                            For g = 0 To pCompositeLayer.Count - 1 'cycle through the composite layer

                                'GET THE NAME of each layer here

                            Next

                        End If
                    Next
0 Kudos
AnatoliiTerentiev
Deactivated User
I can't find how to define that layer is group or composite layer in c#.
if (map.get_Layer(i).GetType() ==  ESRI.ArcGIS.Carto.IGroupLayer ??? ) ...
Can anybody help? Thanks!
0 Kudos
vincentLahaye
Emerging Contributor
hi,

if I remember it's :

if (map.get_Layer(i) is ESRI.ArcGIS.Carto.IGroupLayer)

you can use this link to compare VB and C#, if you need to translate code :
http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

Vincent
0 Kudos
MichaelRobb
Honored Contributor
I will REPOST what I posed:

its in my above post:

If TypeOf pMap.Layer(j) Is ESRI.ArcGIS.Carto.IGroupLayer
0 Kudos