Keep in mind a document can have more than one map,.An IExtension could listen for newly added mapframes and initialize a new layer listener when a new map is added. The extension could manage a list of listeners (one for each map in the document). Or it might be easier to just put it in the MapFrames's IElementProperties.CustomProperty, but I'd test to make sure objects are destroyed gracefully when mapframes are deleted.http://forums.esri.com/Thread.asp?c=93&f=993&t=246221&mc=2#752174
Carlos, This works for me in my class that implements ICommand/IToolControl... Also, it works if the user clicks the Add Data button or drops a layer into the TOC from ArcCatalog.Public Class BFETools Implements ESRI.ArcGIS.SystemUI.ICommand Implements ESRI.ArcGIS.SystemUI.IToolControl Private m_pApp As IApplication Private WithEvents m_pActiveViewEvents As ESRI.ArcGIS.Carto.Map 'as normally, you will set your IApplication in your OnCreate Sub Private Sub m_pActiveViewEvents_ItemAdded(ByVal Item As Object) Handles m_pActiveViewEvents.ItemAdded Dim pMxDoc As IMxDocument = m_pApp.Document Dim pLayer As IFeatureLayer pLayer = pMxDoc.FocusMap.Layer(0) MsgBox(pLayer.Name & " has been Added") End Sub
Public Class BFETools Implements ESRI.ArcGIS.SystemUI.ICommand Implements ESRI.ArcGIS.SystemUI.IToolControl Private m_pApp As IApplication Private WithEvents m_pActiveViewEvents As ESRI.ArcGIS.Carto.Map 'as normally, you will set your IApplication in your OnCreate Sub Private Sub m_pActiveViewEvents_ItemAdded(ByVal Item As Object) Handles m_pActiveViewEvents.ItemAdded Dim pMxDoc As IMxDocument = m_pApp.Document Dim pLayer As IFeatureLayer pLayer = pMxDoc.FocusMap.Layer(0) MsgBox(pLayer.Name & " has been Added") End Sub
if (pCommandItem.Name.ToString() == "File_AddData") { MessageBox.Show("Add Command Executed"); IApplication pApplication = ClsHelper.GetArcGISApplication(); IMxDocument pMxDocument = (IMxDocument)pApplication.Document; IMap pMap = pMxDocument.FocusMap; IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer; MessageBox.Show("Layer name: " + pFeatureLayer.FeatureClass.AliasName); }
pLayer = pMap.Layer(0)
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.