ArcGIS Engine 10 开发手册(3-6)鹰眼图的实现
鹰眼图的实现用到控件如下::
| 
 控件名称  | 
 控件类型  | 
 备注  | 
|---|---|---|
| 
 axMapControl1  | 
 主图  | 
|
| 
 axMapControl2  | 
 鸟瞰图  | 
|
| 
 axToolbarControl1  | 
||
| 
 axTOCControl1  | 
实现分析
鹰眼图的操作主要由以下几个动作,当在一个控件中移动一幅图的时候另一控件中的图也发生 变化,当在主控件中重新加载一幅图的时候,另外一个控件的图也发生相应的变化,同时我们在鸟瞰的控 件中加入一红色边框,注意这个其实是一个面,只是填充的颜色是透明的而已。通过分析我们知道,我们 要添加两个 MapControl 控件,名字分别是 axMapControl1 和 axMapControl2,其中 axMapControl1 为主图, 而 axMapControl2 为鸟瞰图。
代码实现
对于名称为 axMapControl1 的 MapControl 控件,只需要在 axMapControl1 的 OnExtentUpdated 和 OnMapReplaced 中分别添加以下代码:
private void axMapControl1_OnExtentUpdated (object sender,IMapControlEvents2_OnExtentUpdatedEvent e)
{
  // 得到新范围
  IEnvelope pEnvelope = (IEnvelope) e.newEnvelope;
  IGraphicsContainer pGraphicsContainer = 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 = 3;
  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 axMapControl1_OnMapReplaced (object sender,IMapControlEvents2_OnMapReplacedEvent e)
{
  if (axMapControl1.LayerCount > 0)
  {
    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 ();
  }
}
对于名称为 axMapControl2 的 MapControl 控件,只需要在 axMapControl2 的 OnMouseMove 和OnMouseDown 中分别添加以下代码:
private void axMapControl2_OnMouseMove (object sender,IMapControlEvents2_OnMouseMoveEvent e)
{
  if (e.button == 1)
  {
    IPoint pPoint = new PointClass ();
    pPoint.PutCoords (e.mapX, e.mapY);
    axMapControl1.CenterAt (pPoint);
    axMapControl1.ActiveView.PartialRefresh (esriViewDrawPhase.esriViewGeography, null, null);
  }
}
private void axMapControl2_OnMouseDown (object sender,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);
      axMapControl1.ActiveView.PartialRefresh (esriViewDrawPhase.esriViewGeography, null, null);
    } 
    else if (e.button == 2)
    {
      IEnvelope pEnv = axMapControl2.TrackRectangle ();
      axMapControl1.Extent = pEnv;
      axMapControl1.ActiveView.PartialRefresh (esriViewDrawPhase.esriViewGeography, null, null);
    }
  }
}
运行结果
运行后的效果如下:

ArcGIS Engine 10 开发手册全集
ArcGIS Engine 10 开发手册全集: ArcGIS Engine 10 开发手册
相关阅读
声明
1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。
2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。
            
            
    
              
              
              
              
              
              
          
          
          
          
                    
                    
                    
                    
                    
                    
                    
                    
                
                
                
                
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                
                
                
                
                
                
                
                
 
axMapControl2.AddLayer (axMapControl1.get\ _Layer (i));代码有误,请修改一下
应为:axMapControl2.AddLayer (axMapControl1.get_Layer (i));
谢谢反馈。