从ESRI论坛的一个帖子看到.....


下面的一个帖子是ESRI论坛2005年发的,谈论的是TOC控件的一个细节方面的问题,可以看到一些哟意思的东西


Subject ArcGis Engine - Select layer in TOC by code 
Author Nuno Redinha 
Date Aug 03, 2005 
Message
Hi

How do i select a layer in the TOC programatically (VB6)? I'm using arcgis engine, not ArcGis desktop.

Thanks
Nuno Redinha 
  

Author Michael Knight 
Date Aug 03, 2005 
Message There is no select layer or selected layer/item method available in the TOC control.  
   

Author chen Juequan 
Date Aug 03, 2005 
Message Do you mean when you click the layer name in TOC,then you get an ILayer object?If so,you can use ITOCControl::HitTest method.

See the codes below: 
  Private m_pLayer As ILayer

Private Sub TOCControl1_OnMouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
  Dim pMap As IMap
  Dim pLayer As ILayer
  Dim pOther As IUnknown
  Dim pItem As esriTOCControlItem
  Dim pIndex As Variant

  'Determine what kind of item has been clicked on
  TOCControl1.HitTest x, y, pItem, pMap, pLayer, pOther, pIndex
 
  If pItem = esriTOCControlItemLayer Then Set m_pLayer = pLayer
End Sub
 
  Chen Juequan
(chenjuequan@gmail.com)

Nanjing,JiangSu, P.R.China 
  
   
Author Nuno Redinha 
Date Aug 04, 2005 
Message Well, not exactly...
I have a Map and a TOC attached. I have several layers loaded. When i delete one of the layers by code, i would like to select, in the TOC, the above (or below) layer.

So, i cannot use the hittest metod, because i do not click the TOC.

  
Author Michael Knight 
Date Aug 04, 2005 
Message Do you mean select as in "highlight" the layer like in ArcMap? If so, see my previous post.  
   

Author Nuno Redinha 
Date Aug 05, 2005 
Message yes, i would like to "highlight" a layer on the TOC tree, using code.

I'm trying to implement a "identify tool". The user selects a layer in the TOC and activetes the Identify tool. No problem until this point.
The problem is if the user removes that layer, i would like to "highlight" the next (or previous) layer on the TOC tree and sets the "identify tool" to the new "selected" layer.

I saw code example to implement this in ArcMap, but i'm using ArcGis engine, not ArcMap.

Thanks
Nuno  
   

Author chen Juequan 
Date Aug 05, 2005 
Message I think you do not need to highlight a layer in TOC.Use IActiveViewEvents interface to listen to the ItemDeleted event.Delete a layer will trigger this event and when it occurs,pass a new layer to your tool. 
  Private WithEvents m_pActiveViewEvents As Map
Private m_pMap As IMap
Private Sub Command1_Click()
    MapControl1.DeleteLayer 0
End Sub

Private Sub Form_Load()
    Set m_pMap = MapControl1.Map
    Set m_pActiveViewEvents = m_pMap
End Sub

Private Sub m_pActiveViewEvents_ItemDeleted(ByVal Item As Variant)
  If TypeOf Item Is ILayer Then
      MsgBox "A layer has been deleted"
      'write some codes to pass a new layer to your tool.
  End If
End Sub

  
Author Nuno Redinha 
Date Aug 05, 2005 
Message That's exactly my problem: if i pass a new layer to my identify tool after the previous layer has been deleted, the user cannot "see" witch layer the tool is checking, because nothing is "highlighted" in the TOC tree.

The big issue here is that after i delete a layer, no layer is highligted in the TOC, and i would like to be able to highligt it, by code...

Thanks
Nuno Redinha  
   
Author chen Juequan 
Date Aug 05, 2005 
Message Let me know how you pass a layer to your Identify tool. 
  Chen Juequan 

  

Author Michael Knight 
Date Aug 08, 2005 
Message That's what I said in my earlier post. There is no method available in ArcGIS Engine to highlight layers in the TOCControl. A probable work around would be to use a drop down list to "set" or "show" which layer is active.  
   

Author Eric Elder 
Date Aug 23, 2005 
Message Everytime you click on a layer in the TOC, store that layer and the layer index number to variables. When you delete the active layer from the map/TOC, subtract 1 from the stored index number, that will give you the layer above the one you just deleted, then store this new layer as the active layer. I did it in my code, I just can't find it at the moment.

Eric  
   

Author Nuno Redinha 
Date Sep 07, 2005 
Message
ok, but how do i actualy make it selected (turn the layer name to blue in the TOC tree), so the user can see that it is the selected layer?

Can you please check for your code and post it here?

Thanks
Nuno Redinha  
   
Author Eric Elder 
Date Sep 07, 2005 
Message The layer names turns blue on the mouse up event when you click on the layer name in the TOC. I have not found any other way. I am unable to change the blue selection if I change the active layer in the code.

Eric 
   
• Top Print Reply  Alert Moderator   
Subject Re: ArcGis Engine - Select layer in TOC by code 
Author Michael Knight 
Date Sep 07, 2005 
Message There is no method in the TOCControl to show a layer as selected (highlight it), unlike the TOC in ArcMap. 
   
• Top Print Reply  Alert Moderator   
Subject Re: ArcGis Engine - Select layer in TOC by code 
Author Nuno Redinha 
Date Sep 08, 2005 
Message
Michael,

I was trying not to accept that fact... But i guess your are right, until now no one found the answer...

If somewone from ESRI is listening... Check this issue please!

Tanks all for your help.

Regards
Nuno Redinha  
   

Author Eric Elder 
Date Feb 14, 2007 
Message This can now be done in 9.2.

 
  //Selecting a layer in the focus map
axTOCControl1.SelectItem(axTOCControl1.ActiveView.FocusMap.get_Layer(0));

 

posted on 2007-06-09 11:03  GISAddictor  阅读(1305)  评论(2编辑  收藏  举报