您的位置:首页 > 编程语言 > C#

C#+ArcEngine问题小结(一)

2007-11-13 13:27 190 查看
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);
}

T.B.D.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: