Skip to main content
1 of 2
Feng Ma
  • 121
  • 5

Construct a subclass inherited from GroupLayerClass, and construct a IGroupLayerEvent interface to monitor whether or not to add layers to the layer group.

public delegate void IGroupLayerEvents_ItemAddedEventHandler(object Item);
public delegate void IGroupLayerEvents_ItemDeletedEventHandler(object Item);

public interface IGroupLayerEvents
{
    event IGroupLayerEvents_ItemAddedEventHandler ItemAdded;
    event IGroupLayerEvents_ItemDeletedEventHandler ItemDeleted;
}
public class GroupLayerClassEx:GroupLayerClass,IGroupLayerEvents
{
    public event IGroupLayerEvents_ItemAddedEventHandler ItemAdded;
    public event IGroupLayerEvents_ItemDeletedEventHandler ItemDeleted;

    public override void Add(ILayer layer)
    {
        base.Add(layer);
        if (ItemAdded != null)
        {
            ItemAdded(layer);
        }
    }

    public override void Clear()
    {
        if (ItemDeleted != null)
        {
            ICompositeLayer pCompositeLayer = this as ICompositeLayer;
            for (int i = 0; i < pCompositeLayer.Count; i++)
            {
                ILayer pCurrentLayer = pCompositeLayer.get_Layer(i);
                ItemDeleted(pCurrentLayer);
            }
        }
        base.Clear();
    }

    public override void Delete(ILayer Layer)
    {
        base.Delete(Layer);
        if (ItemDeleted != null)
        {
            ItemDeleted(Layer);
        }
    }
}
Feng Ma
  • 121
  • 5