agrineersumit

How to add Layers using IEnumLayer for autoArrange

Discussion created by agrineersumit on Sep 4, 2012
Latest reply on Sep 24, 2012 by agrineersumit
The following code help to add layers in Map using IMap.AddLayers method for auto arrangement of point layers above line layers above polygon layers:


IMap pMap;
            EnumExt test = new EnumExt();
            pMap = m_hookHelper.ActiveView.FocusMap;
            IWorkspaceFactory pWrkFac = new FileGDBWorkspaceFactory();
            IWorkspace pWrk = pWrkFac.OpenFromFile(@"C:\Program Files (x86)\ArcGIS\DeveloperKit10.0\Samples\data\California\California.gdb",0);
            IFeatureLayer pLyr = new FeatureLayerClass();
            IEnumDataset pEnumDataset = pWrk.get_Datasets(esriDatasetType.esriDTFeatureClass);
            IDataset pDataset;
            IFeatureClass pFeatClass ;
          
          
            IEnumDatasetName pDatasetName;
            pDatasetName = pWrk.get_DatasetNames(esriDatasetType.esriDTFeatureClass);
            IName pName;
            while (pEnumDataset.Next() != null)
            {
                try
                {
                    pName = pDatasetName.Next() as IName;
                   

                    pEnumLayer = pFac.CreateLayersFromName(pName);
                  
                
                   pMap.AddLayers(pEnumLayer, true);
                }
                catch (Exception e)
                {
                 
                    MessageBox.Show(e.Message);
                }
            }

            m_hookHelper.ActiveView.Refresh();

Outcomes