按照Engine+开发手册ArcEngine_10.0_C#二次开发编写的鹰眼的代码,运行时鹰眼不显示!

代码是完全按照《Engine+开发手册ArcEngine_10.0_C#二次开发》编写的,运行没有错误,但是鹰眼就是不显示。
已邀请:

朱新颖

赞同来自: Danranhutu 石羽

比如添加事件(在添加完mxd后执行下面代码):
  IActiveViewEvents_Event events = axMapControl1.ActiveView as IActiveViewEvents_Event;
            events.ItemAdded += new IActiveViewEvents_ItemAddedEventHandler(ItemAdded);
然后在ItemAdded方法中执行同步:
  private void ItemAdded(System.Object Item)
        {

            // TODO: Add your code here
            if (this.axMapControl1.LayerCount > 0)
            {
                              
                axMapControl2.AddLayer(Item as ILayer);                
                axMapControl2.Extent = axMapControl1.Extent;
                axMapControl2.Refresh();

            }
        }
注意,新添加的图层需要与mxd的已有图层能同时显示出来,也就是说空间参考一致

朱新颖

赞同来自: 石头

原因:Add Data新加栅格数据时没有触发相应的事件,所以MapControl2中不会加载该数据。
可以尝试添加IActiveViewEvents.ItemAdded事件,在该事件的处理函数中执行 

Danranhutu - 爱知乎,爱AE开发

赞同来自:

这个是Form的完整代码using ESRI.ArcGIS.Output;
using System;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;



namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}



private void axLicenseControl1_Enter(object sender, EventArgs e)
{

}

private void axToolbarControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IToolbarControlEvents_OnMouseDownEvent e)
{

}

private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e)
{
if (this.axMapControl1.LayerCount > 0)
{
this.axMapControl2.Map=new MapClass();
for (int i = 0; i <= (axMapControl1.Map.LayerCount - 1); i++)
{
axMapControl2.AddLayer(axMapControl1.get_Layer(i));
}
axMapControl2.Extent = axMapControl1.Extent;
axMapControl2.Refresh();

}
}


private void axMapControl2_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
if (axMapControl2.Map.LayerCount > 0)
{
if (e.button == 1)
{
IPoint pPoint = new PointClass();
pPoint.PutCoords(e.mapX, e.mapY);
axMapControl1.CenterAt(pPoint);
this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
else if (e.button == 2)
{
IEnvelope pEnv = axMapControl2.TrackRectangle();
axMapControl1.Extent = pEnv;
this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
}
}

private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)
{
//得到新范围
IEnvelope pEnvelope = (IEnvelope)e.newEnvelope;
IGraphicsContainer pGraphicsContainer =this.axMapControl2.Map as IGraphicsContainer;
IActiveView pActiveView = pGraphicsContainer as IActiveView;

//在绘制前,清除axMapControl2中的任何图形元素
pGraphicsContainer.DeleteAllElements();
IRectangleElement pRectangleEle =new RectangleElementClass();
IElement pElement = pRectangleEle as IElement;
pElement.Geometry = pEnvelope;
//设置鹰眼图中的红线框
IRgbColor pColor = new RgbColorClass();
pColor.Red = 255;
pColor.Green = 0;
pColor.Blue = 0;
pColor.Transparency = 255;
//产生一个线符号对象
ILineSymbol pOutline = new SimpleLineSymbolClass();
pOutline.Width = 1;
pOutline.Color = pColor;
//设置颜色属性
pColor = new RgbColorClass();
pColor.Red = 255;
pColor.Green = 0;
pColor.Blue = 0;
pColor.Transparency = 0;
//设置填充符号的属性
IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
pFillSymbol.Color = pColor;
pFillSymbol.Outline = pOutline;
IFillShapeElement pFillShapeEle = pElement as IFillShapeElement;
pFillShapeEle.Symbol=pFillSymbol;
pGraphicsContainer.AddElement((IElement)pFillShapeEle,0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);
}

private void axMapControl2_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
{
if (e.button == 1)
{
IPoint pPoint = new PointClass();
pPoint.PutCoords(e.mapX, e.mapY);
this.axMapControl1.CenterAt(pPoint);
this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
}
}
}

xiaoyaoyeren

赞同来自:

这个问题是怎么解决的?

Danranhutu - 爱知乎,爱AE开发

赞同来自:

目前还没有解决,不过如果打开MXD文件的话是可以正常显示的,但是如果单单是加载图层就不行。有网友讲是坐标系统的问题,但是我还是初学,不晓得如何使得坐标系统一致起来
 

要回复问题请先登录注册