public static void MoveLayer(IMap pMap, ILayer pLayer, enumMoveTo moveTo) { if (pMap == null || pLayer == null) { return; } int LayerIndex = -1; int index = 0; if (LayerUtil.IsFirstLevelLayer(pMap, pLayer)) { LayerIndex = LayerUtil.GetLayerIndex(pMap, pLayer.Name); if (LayerIndex > -1) { if (moveTo == enumMoveTo.enumMoveTop) { pMap.MoveLayer(pLayer, 0); } else if (moveTo == enumMoveTo.enumMoveBottom) { index = (LayerIndex - 1) > 0 ? (LayerIndex - 1) : 0; pMap.MoveLayer(pLayer, pMap.LayerCount - 1); } else if (moveTo == enumMoveTo.enumMoveUp) { var toIndex = LayerIndex - 1; if (toIndex < 0) { toIndex = 0; } pMap.MoveLayer(pLayer, toIndex); } else if (moveTo == enumMoveTo.enumMoveDown) { if (LayerIndex < pMap.LayerCount - 1) { pMap.MoveLayer(pLayer, LayerIndex + 1); } } } } else { IGroupLayer pBelongGroupLayer = GetBelongGroupLayer(pMap, pLayer); if (pBelongGroupLayer != null) { LayerIndex = LayerUtil.GetLayerIndexInGroupLayer(pBelongGroupLayer, pLayer); //当pLayer的直接组图层不是pBelongGroupLayer时无效!!! if (LayerIndex > -1) { if (moveTo == enumMoveTo.enumMoveTop) { MapUtil.MoveLayerInGroupLayer(pMap, pBelongGroupLayer, pBelongGroupLayer, pLayer, 0); } else if (moveTo == enumMoveTo.enumMoveBottom) { ICompositeLayer pCompositeLayer = pBelongGroupLayer as ICompositeLayer; MapUtil.MoveLayerInGroupLayer(pMap, pBelongGroupLayer, pBelongGroupLayer, pLayer, pCompositeLayer.Count - 1); } else if (moveTo == enumMoveTo.enumMoveUp) { index = (LayerIndex - 1) > 0 ? (LayerIndex - 1) : 0; MapUtil.MoveLayerInGroupLayer(pMap, pBelongGroupLayer, pBelongGroupLayer, pLayer, index); } else if (moveTo == enumMoveTo.enumMoveDown) { if (LayerIndex < LayerUtil.GetLayerCountInGroupLayer(pBelongGroupLayer, false) - 1) { int count = (pBelongGroupLayer as ICompositeLayer).Count; index = (LayerIndex + 1) > count ? (LayerIndex + 1) :(count - 1); MapUtil.MoveLayerInGroupLayer(pMap, pBelongGroupLayer, pBelongGroupLayer, pLayer, index); } } } } } }