3

I am having problems in ArcObjects. I am struggling to get to the individual (feature-)layers inside a GroupLayer. Does anyone know how to do that ?

4

Try this:

public List<ILayer> GetLayers(string groupLayerName)
{

    ICompositeLayer compositeLayer = GetGroupLayer(groupLayerName);
    List<ILayer> layers = new List<ILayer>();

    if (compositeLayer != null)
    {
        for (int j = 0; j < compositeLayer.Count; j++)
        {
            layers.Add(new Layer(compositeLayer.Layer[j]));
        }
    }
    return layers;
}

ICompositeLayer GetGroupLayer(string groupLayerName)
{
     var mapLayers = _map.Layers;
     for (var layer = mapLayers.Next(); layer != null; layer = mapLayers.Next())
     {
            var comLayer = layer as ICompositeLayer;
            var groupLayer = layer as IGroupLayer;
            if ((comLayer != null) && (groupLayer != null) && (layer.Name.Equals(groupLayerName)))
                return groupLayer;
     }
}
3

Cast the group layer to ICompositeLayer which allows you to access the individual sublayers.

Provides access to members that work with a collection of layers that behaves like a single layer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.