How to add Layers using IEnumLayer for autoArrange

472
2
09-04-2012 09:46 AM
SumitSharma
New Contributor III
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();
Reply
0 Kudos
2 Replies
CharlieRichman
New Contributor
Fabulous -- but what's EnumExt()?

You don't seem to define m_hookHelper or pFac either. 

I'd like to be able to start with a path to a layerfile and add the contents (which could include a group layer) via this mechanism...


Charlie Richman
District of Columbia Office of Planning
Reply
0 Kudos
SumitSharma
New Contributor III
Hello Charlie,

You don't require EnumExt as this was something I was doing for other test inside the code solution.

As this was an engine application therefore m_hookHelper is predefined inside the engine template. If you are creating ArcGIS Desktop application then you can use IMxDocument to get IActiveView.

Let me know if you require some more details!!

Sumit
Reply
0 Kudos