ArcGIS 鹰眼地图功能实现

来源:互联网 发布:阿尔法软件下载 编辑:程序博客网 时间:2024/05/22 12:12

ArcGIS地图鹰眼功能实现:

1.创建ArcEngine winform程序,界面如下图所示


2、具体代码如下所示

using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.IO;using System.Runtime.InteropServices;using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.ADF;using ESRI.ArcGIS.SystemUI;using ESRI.ArcGIS.Geometry;using ESRI.ArcGIS.Display;namespace MapControl{    public sealed partial class MainForm : Form    {        #region class private members        private IMapControl3 m_mapControl = null;        private string m_mapDocumentName = string.Empty;        #endregion        #region class constructor        public MainForm()        {            InitializeComponent();        }        #endregion        private void MainForm_Load(object sender, EventArgs e)        {            //get the MapControl            m_mapControl = (IMapControl3)axMapControl1.Object;            //disable the Save menu (since there is no document yet)            menuSaveDoc.Enabled = false;            //加载MXD数据            this.axMapControl1.LoadMxFile(Application.StartupPath +@"\Map\Map.mxd");            this.axMapControl1.Extent = this.axMapControl1.FullExtent;            this.axMapControl1.ActiveView.Refresh();        }        #region Main Menu event handlers        private void menuNewDoc_Click(object sender, EventArgs e)        {            //execute New Document command            ICommand command = new CreateNewDocument();            command.OnCreate(m_mapControl.Object);            command.OnClick();        }        private void menuOpenDoc_Click(object sender, EventArgs e)        {            //execute Open Document command            ICommand command = new ControlsOpenDocCommandClass();            command.OnCreate(m_mapControl.Object);            command.OnClick();        }        private void menuSaveDoc_Click(object sender, EventArgs e)        {            //execute Save Document command            if (m_mapControl.CheckMxFile(m_mapDocumentName))            {                //create a new instance of a MapDocument                IMapDocument mapDoc = new MapDocumentClass();                mapDoc.Open(m_mapDocumentName, string.Empty);                //Make sure that the MapDocument is not readonly                if (mapDoc.get_IsReadOnly(m_mapDocumentName))                {                    MessageBox.Show("Map document is read only!");                    mapDoc.Close();                    return;                }                //Replace its contents with the current map                mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);                //save the MapDocument in order to persist it                mapDoc.Save(mapDoc.UsesRelativePaths, false);                //close the MapDocument                mapDoc.Close();            }        }        private void menuSaveAs_Click(object sender, EventArgs e)        {            //execute SaveAs Document command            ICommand command = new ControlsSaveAsDocCommandClass();            command.OnCreate(m_mapControl.Object);            command.OnClick();        }        private void menuExitApp_Click(object sender, EventArgs e)        {            //exit the application            Application.Exit();        }        #endregion        //加载主地图的时候,也加载鹰眼地图数据        private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)        {            //get the current document name from the MapControl            m_mapDocumentName = m_mapControl.DocumentFilename;            //if there is no MapDocument, diable the Save menu and clear the statusbar            if (m_mapDocumentName == string.Empty)            {                menuSaveDoc.Enabled = false;                statusBarXY.Text = string.Empty;            }            else            {                //enable the Save manu and write the doc name to the statusbar                menuSaveDoc.Enabled = true;                statusBarXY.Text = System.IO.Path.GetFileName(m_mapDocumentName);            }            if (this.axMapControl1.LayerCount > 0)            {                this.axMapControl2.ClearLayers();                this.axMapControl2.Map = new ESRI.ArcGIS.Carto.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 axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)        {            statusBarXY.Text = string.Format("{0}, {1}  {2}", e.mapX.ToString("#######.##"), e.mapY.ToString("#######.##"), axMapControl1.MapUnits.ToString().Substring(4));        }        private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)        {            //得到新范围            IEnvelope pEnvelop = (IEnvelope)e.newEnvelope;            try            {                if (this.axMapControl2.Map.LayerCount <= 0) return;            }            catch { return; }            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 = pEnvelop;            //设置鹰眼中的红线框            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);        }        /// <summary>        /// 鹰眼地图移动,改变主地图        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        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);                    this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);                }                else if (e.button == 2)                {                    IEnvelope pEnv = this.axMapControl2.TrackRectangle();                    axMapControl1.Extent = pEnv;                    this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);                }            }        }        /// <summary>        /// 鹰眼地图右键移动,改变主地图        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void axMapControl2_OnMouseMove(object sender, 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);            }        }          }}
3.具体成果图如下所示



0 0