C#+ArcEngine問題小結(一)

來源:互聯網
上載者:User

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);
  }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.