C#+ArcEngine问题小结(一)

1、MapControl的CurrentTool=null不起作用:
   在VB中使用MapControl.CurrentTool=nothing即可,而使用C#就不灵了。解决办法如下所示,先做一转换即可。
    IMapControl2 pMainMap2=(IMapControl2)axMapMain.Object;
    pMainMap2.CurrentTool=null;

2、TocControl的HitTest不起作用:
该问题与上一问题类似,做以下处理
   ITOCControl pTOCControl = (ITOCControl)axTOCCtrl.Object;
   pTOCControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);

3、通过TocControl 控件的事件调换图层:

  ILayer pMoveLayer;  
  int iToLayerIndex;
  private void axTOCCtrl_OnMouseDown(object sender, AxESRI.ArcGIS.TOCControl.ITOCControlEvents_OnMouseDownEvent e){
   esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
   IBasicMap map = null; 
   ILayer layer = null;
   object other = null; 
   object index = null;
   ITOCControl pTOCControl = (ITOCControl)axTOCCtrl.Object;
   pTOCControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
   axMapMain.CustomProperty = layer;
   if(e.button==1){
    if(item==esriTOCControlItem.esriTOCControlItemLayer){
     if(layer is IAnnotationSublayer) {
      return;
     }
     else {
      pMoveLayer=layer;
     }
     axTOCCtrl.MousePointer=esriControlsMousePointer.esriPointerHotLink;
    }
   }

  }

  private void axTOCCtrl_OnMouseUp(object sender, AxESRI.ArcGIS.TOCControl.ITOCControlEvents_OnMouseUpEvent e){
   if(e.button==1)  {
    esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
    IBasicMap map = null; 
    ILayer layer = null;
    object other = null; 
    object index = null;   
    ITOCControl pTOCControl = (ITOCControl)axTOCCtrl.Object;
    pTOCControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);  
    axMapMain.CustomProperty = layer;
    IMap pMap=axMapMain.ActiveView.FocusMap;
    if(item == esriTOCControlItem.esriTOCControlItemLayer || layer!=null) {
     if(pMoveLayer!=layer) {
      ILayer pTempLayer;
      
      for(int i=0;i<pMap.LayerCount;i++)  {
       pTempLayer=pMap.get_Layer(i);
       if(pTempLayer==layer) {
        iToLayerIndex=i;
       }

      }
      pMap.MoveLayer(pMoveLayer,iToLayerIndex);
      axMapMain.ActiveView.Refresh();
     }
    }
    axTOCCtrl.MousePointer=esriControlsMousePointer.esriPointerArrow;
   }  
  }


4、鹰眼的实现
  private void drawMapEagleRect(IMap pMap, int iRed, int iGreen, int iBlue, int iWidth, object newEnvelope){
   IEnvelope pNewMainEnv = (IEnvelope)newEnvelope;

   IGraphicsContainer pGraphCon = pMap as IGraphicsContainer;
   IActiveView pActiveView = pGraphCon as IActiveView;
   pGraphCon.DeleteAllElements();
   //
   IRectangleElement pRectEle = new RectangleElementClass();
   IElement pEle = pRectEle as IElement;
   pEle.Geometry =pNewMainEnv;
   //
   IRgbColor pColor = new RgbColorClass();
   pColor.Red = iRed;
   pColor.Green = iGreen;
   pColor.Blue =iBlue;
   pColor.Transparency = (byte)iRed;
   //
   ILineSymbol pOutline = new SimpleLineSymbolClass();
   pOutline.Width = iWidth;
   pOutline.Color = pColor;
   //
   pColor = new RgbColorClass();
   pColor.Red = iRed;
   pColor.Green = iGreen;
   pColor.Blue = iBlue;
   pColor.Transparency = 0;
   //
   IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
   pFillSymbol.Color = pColor;
   pFillSymbol.Outline = pOutline;

   IFillShapeElement pFillShapeEle = pEle as IFillShapeElement;
   pFillShapeEle.Symbol = pFillSymbol;

   pGraphCon.AddElement((IElement)pFillShapeEle, 0);

   pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);    
  } 


  private void axMapMain_OnMapReplaced(object sender, AxESRI.ArcGIS.MapControl.IMapControlEvents2_OnMapReplacedEvent e) {
   if(!axMapMain.DocumentFilename.Equals("")){
    axMapEagle.LoadMxFile(axMapMain.DocumentFilename);
    axMapEagle.Extent=axMapEagle.FullExtent;
    drawMapEagleRect(axMapEagle.Map,255,0,0,1,axMapMain.Extent.Envelope);
   }
  }


  private void axMapEagle_OnMouseDown(object sender, AxESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvent e) {
   IPoint pPoint=new PointClass();
   pPoint.PutCoords(e.mapX,e.mapY);
   axMapMain.CenterAt(pPoint);
  }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值