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