Take the 2-minute tour ×

How can i find the type of the layers in TOC ? these types are very important to me :

1.layer (that has a valid datasource)

2.layer (that lose its datasource because of changing the address of its datasource )


And i want to know about the index of the layer that we have with ILayer. A function like this : Public Function GetLayerIndex(mLayer as ILayer) as long

share|improve this question

1 Answer 1

You examine the interfaces which a particular layer implements. All layers implement ILayer. If you open up the documentation link for the interface, you will see which classes implement this general interface.

Common layer types (in context of your question) are FeatureLayer (implements IFeatureLayer among others), GroupLayer (ICompositeLayer, IGroupLayer) etc. You get the idea - when exploring the plethora of interfaces layers can implement, it's good to refer to the list of classes implementing ILayer as a great starting point.

As for the second part, layers which are not connected due to an inaccessible data source will typically be marked as invalid (red exclamation mark). The ILayer.Valid indicates whether this is or is not the case.

Finally, the third part of your question. Layer indices are assigned either at the top level (the index which goes as a parameter to IMap.Layer) or within a particular layer container, e. g. a composite (group) layer. The only way to get retrieve the index for an existing layer is to loop through the map or a composite layer and compare the items. This will work only at a single level and will not work reliably when layers are nested with group layers. That being said, layer indices are generally not a good idea to refer to layers.

share|improve this answer
+1 Good answer. While I agree that using indices is not best practice, it is nevertheless common practice - Esri's REST api uses indices to access layers within a mapservice. –  Kirk Kuykendall Jul 30 '11 at 21:02
Absolutely right, but aren't indices in map services different? As far as I know, in ArcGIS Server map services they are unique for the whole service. And even in this case I do not believe it's ideal - every time you add a layer somewhere in the middle, your layer indices shift. Luckily at AGS 10, at least for WMS services, there is a new option to use the layer name from MXD/MSD as the WMS layer name, instead of the index. –  Petr Krebs Jul 31 '11 at 7:51
Yeah, whenever a new layer is added to a mapservice all the client web apps need to be re-config'd. It is possible to make an extra query at initialization time to build a dictionary associating name with index (id), but that is a pain. Sure would simplify things if Esri just provided some Layer property whose uniqueness (UniqueName) is enforced along with a method to find layer by that property. –  Kirk Kuykendall Jul 31 '11 at 15:15

Your Answer


