ArcGIS二次开发基础教程(02):地图导航和鹰眼

ArcGIS二次开发基础教程(02):地图导航和鹰眼

地图导航(主要是调用命令和工具)

  1. 地图的放缩和漫游
if(axMapControl1.CurrentTool == null)
{
    ICommand icc;
    //地图放大
	ITool tool = new ControlsMapZoomInToolClass();
    //地图缩小
    //ITool tool = new ControlsMapZoomOutToolClass();
    //地图漫游
    //ITool tool = new ControlsMapPanToolClass();
    icc = tool as ICommand;
    icc.OnCreate(axMapControl1.Object);//钩子函数
    icc.OnClick();
}
  1. 全局地图

    ICommand icc = new ControlsFullExtentCommandClass();
    icc.OnCreate(axMapControl1.Object);
    icc.OnClick();
    

鹰眼

//注意:只有从mxd文件中加载图层鹰眼才会出现  axMapControl1是主地图 axMapControl2为鹰眼图
private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
{
    axMapControl2.Map.ClearLayer();
    if(axMapControl1.LayerCount>0)
    {
        //从下往上获取图层添加到鹰眼图中防止覆盖
        for(int i= axMapControl1.LayerCount-1;i>=0;i--)
        {
            ILayer layer = axMapControl1.get_Layer(i);
            IObjectCopy copy = new ObjectCopyClass();
            ILayer myLayer = copy.Copy(layer) as ILayer;
            axMapControl2.AddLayer(layer);
        }
        //设置相同的空间参考
        axMapControl2.SpatialReferencr = axMapControl1.SpatialReference;
        //鹰眼图的全局为主地图的当前视图
        axMapControl2.FullExtent = axMapControl1.Extent;
        //每次主地图图层增减都刷新
        axMapControl2.Refresh();
    }
}
//当主地图变化时,鹰眼图框变化
private void axMapControl2_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
{
    //创建一个矩形元素并转换为元素
    IElement ele = new RectangleElementClass() as IElement;
    //获取主地图的视图
    IEenvlop env = axMapControl1.Extent;
    ele.Geometry = env as IGeometry;
    //外轮廓线
    ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
    IRGBColor color1 = new RGBColorClass();
    color1.Red = 255;
    color1.Green = 0;
    color1.Blue = 0;
    //透明度为255即不透明
    color1.Tranparency = 255;
    lineSymbol.Color= color1;
    lineSymbol.Width = 2;
    ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
    IRGBColor color2 = new RGBColorClass();
    color2.Red = 255;
    color2.Green = 0;
    color2.Blue = 0;
    //透明度为0即完全透明 
    color2.Tranparency = 0;
    fillSymbol.Color = color2;
    fillSymbol.Outline = lineSymbol;
    //实现线框的生成
    IFillShapeElement fillShapeElement = ele as IFillShapeElement;
    fillShapeElement.Symbol = fillSymbol;
    //图形容器
    IGraphicsContainer graphicsContainer = axMapControl2.Map as IGraphicsContainer;
    //删掉以前的元素
    graphicsContainer.DeleteAllElements();
    //添加新元素
    graphicsContainer.AddElement(fillShapeElement as IElement);
    axMapControl2.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
//鹰眼图的鼠标点击事件
 private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
 {
     if(e.Button == 1)
     {
         //将主地图视图中心移到点击处
         IPoint point = new PointClass();
         point.PutCoords(e.mapX,e.mapY);
         axMapControl1.CenterAt(point);
         axMapControl1.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
     }
     else
     {
         //将主地图视图变为从鹰眼图获取的轨迹矩形
         IEnvelop env = axMapControl2.TrackRectangle;
         axMapCOntrol1.Extent = env;
         axMapControl1.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
	 }
 }
//鹰眼图的鼠标移动事件
 private void axMapControl2_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
 {
     if(e.Button == 1)
     {
     	IPoint point = new PointClass();
     	point.PutCoords(e.mapX,e.mapY);
     	axMapControl1.CenterAt(point);
    	axMapControl1.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
     }
 }

鹰眼效果:

在这里插入图片描述
历届GIS应用技能大赛开发题答案点这里,尚在不定期更新中

  • 6
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值