鹰眼图实现

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;

namespace AEKF_yingyan
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //窗体加载打开地图文档
        private void Form1_Load(object sender, EventArgs e)
        {
            loadMapDocument();
        }
        //打开地图文档方法
        private void loadMapDocument()
        {
            System.Windows.Forms.OpenFileDialog openFileDialog;
            openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "打开地图文档";
            openFileDialog.Filter = "map document(*.mxd)|*.mxd";
            openFileDialog.ShowDialog();
            string filepath = openFileDialog.FileName;
            if (filepath != "" && filepath != null)
            {
                if (axMapControl1.CheckMxFile(filepath))
                {
                    axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;
                    axMapControl1.LoadMxFile(filepath, 0, Type.Missing);
                    axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
                }
                else
                {
                    MessageBox.Show(filepath+"不是有效地图文档");
                }
            }
        }
        //打开鹰眼地图方法
        private void loadEagleEyeDocument()
        {
            System.Windows.Forms.OpenFileDialog openFileDialog;
            openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "打开鹰眼地图";
            openFileDialog.Filter = "map document(*.mxd)|*.mxd";
            openFileDialog.ShowDialog();
            string filepath = openFileDialog.FileName;
            if (filepath != "" && filepath != null)
            {
                if (axMapControl2.CheckMxFile(filepath))
                {
                    axMapControl2.MousePointer = esriControlsMousePointer.esriPointerHourglass;
                    axMapControl2.LoadMxFile(filepath, 0, Type.Missing);
                    axMapControl2.MousePointer = esriControlsMousePointer.esriPointerDefault;
                }
                else
                {
                    MessageBox.Show(filepath+"不是有效地图");
                }
            }
        }

       // axMapControl1控件的_OnMapReplaced事件
        private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
        {
            loadEagleEyeDocument();
        }
        //axmapconteol1的onmousedown事件
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if (e.button == 1)
            {
                axMapControl1.Extent = axMapControl1.TrackRectangle();
                axMapControl1.Refresh(esriViewDrawPhase.esriViewBackground,null,null);
            }
            else if (e.button == 2)
            {
                axMapControl1.Pan();
                axMapControl1.Refresh(esriViewDrawPhase.esriViewBackground,null,null);
            }
        }

       // axMapControl1的_OnExtentUpdated事件
        private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
        {
            IEnvelope envelope = (IEnvelope)e.newEnvelope;
            IGraphicsContainer graphicsContainer = axMapControl2.Map as IGraphicsContainer;
            IActiveView activeview = graphicsContainer as IActiveView;
            //设置鹰眼图中的红线
            //产生一个线符号
            ILineSymbol outlinesymbol = new SimpleLineSymbolClass();
            outlinesymbol.Width = 2;
            outlinesymbol.Color = GetColor(255,0,0,255);
            //设置颜色属性
            //设置填充符号
            IFillSymbol fillsymbol = new SimpleFillSymbolClass();
            fillsymbol.Color = GetColor(9,0,0,0);
            fillsymbol.Outline = outlinesymbol;
            IFillShapeElement fillShapeElement = outlinesymbol as IFillShapeElement;
            fillShapeElement.Symbol = fillsymbol;
            graphicsContainer.AddElement((IElement)fillShapeElement, 0);
            activeview.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);

        }
        private IRgbColor GetColor(int r, int g, int b, int t)
        {
            IRgbColor rgbColor = new RgbColorClass();
            rgbColor.Red = r;
            rgbColor.Green = g;
            rgbColor.Blue = b;
            rgbColor.Transparency=(byte)t;
            return rgbColor;
        }
        //axMapControl2的_OnMouseDown事件
        private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            IPoint point = new PointClass();
            point.PutCoords(e.mapX,e.mapY);
            axMapControl1.CenterAt(point);
        }

 


    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值