获取图层所在的图层组

        /// 
        /// 递归返回图层所在的图层组
        /// 
        /// 
        /// 
        /// 
        public static IGroupLayer GetGroupLayer(ILayer pGroupLayer, ILayer pLayer)
        {
            IGroupLayer ppGroupLayer = null;
            if (pGroupLayer is IGroupLayer || pGroupLayer is ICompositeLayer)   //判断是否是groupLayer
            {
                ICompositeLayer pCompositeLayer = pGroupLayer as ICompositeLayer;
                for (int i = 0; i < pCompositeLayer.Count; i++)
                {
                    ILayer pSubLayer = pCompositeLayer.Layer[i];   //递归
                    if (pSubLayer != pLayer)
                    {
                        ppGroupLayer = GetGroupLayer(pSubLayer, pLayer);
                        if (ppGroupLayer != null)
                        {
                            break;
                        }
                    }
                    else
                    {
                        ppGroupLayer = pGroupLayer as IGroupLayer;
                        break;
                    }
                }
            }
            return ppGroupLayer;
        }

 

你可能感兴趣的:(ArcEngine开发)