首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

AE兑现鹰眼功能

2012-11-03 
AE实现鹰眼功能效果图:源代码:using Systemusing System.Collections.Genericusing System.ComponentMod

AE实现鹰眼功能

效果图:

AE兑现鹰眼功能

源代码:

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.Carto;using ESRI.ArcGIS.Geometry;using ESRI.ArcGIS.Display;namespace 鹰眼功能{    public partial class Form1 : Form    {        public Form1()        {            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);            InitializeComponent();        }        //--1、让两个MapControl显示的数据保持一致,让两个控件的数据共享        //--1、OnMapReplaced当mapcontrol1中的地图被替换时,该方法自动加载主空间中所有的图层对象到鹰眼中        //--1、而如果使用传递两个控件之间的Map属性这种方法完成数据共享,因为map属性同时传递了地图对象的范围和比例,        //--1、造成鹰眼时图中不能够显示完整的地图        private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e)        {            //获得mapcontrol1的map对象            IMap map = axMapControl1.Map;                        //遍历map中的图层,都添加到mapcontrol2中            for (int i = 0; i < map.LayerCount; i++)            {                axMapControl2.AddLayer(map.get_Layer(i));            }        }        //--2、在主控件中使用鼠标拖拽视图的时候,鹰眼控件中出现红色矩形框        //--2、该方法发生在主视图的范围发生变换后,        private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)        {            //得到新范围            IEnvelope2 envelope = e.newEnvelope as IEnvelope2;            //生成一个矩形要素            IRectangleElement rectangleelement = new RectangleElementClass();            //得到一个要素并将矩形要素传入            IElement element = rectangleelement as IElement;            //将新范围赋值给要素的几何外形            element.Geometry = envelope;            //得到RGBColor对象            IRgbColor color = new RgbColorClass();            //设置Color的RGB值            color.RGB = 00000255;            //设置透明度            color.Transparency = 255;            //产生一个线状符号            ILineSymbol lineSymbool = new SimpleLineSymbolClass();            //设置线状符号的属性            lineSymbool.Width = 1;            lineSymbool.Color = color;            //设置颜色属性            color.RGB = 255;            color.Transparency = 0;            //生成一个填充符号用来填充矩形区域            IFillSymbol fillSymbol = new SimpleFillSymbolClass();            //设置填充符号的属性            //填充色            fillSymbol.Color = color;            //外轮廓            fillSymbol.Outline = lineSymbool;            //得到一个填充图形要素,AE帮助中对IFillShapElement的解释为            /*IFillShapeElement is a generic interface implemented by all 2d elements (CircleElement,             * EllipseElement, PolygonElement, and RectangleElement).             * Use this interface when you want to retrieve or set the fill symbol being used by one              * of the fill shape elements.            */            IFillShapeElement fillShapElement = element as IFillShapeElement;            //将填充符号传入Symbol中            fillShapElement.Symbol = fillSymbol;            //最后将填充图形要素赋值给要素类            element = fillShapElement as IElement;            //得到图像容器,并将mapcontrol2的map传入            IGraphicsContainer graphicsContainer = axMapControl2.Map as IGraphicsContainer;            //得到一个活动视图并将graphicscontainer传入            IActiveView activeView = graphicsContainer as IActiveView;            //在绘制新的矩形框前,清楚Map对象中的任何图形元素            graphicsContainer.DeleteAllElements();            //将要素添加到图像容器中,并将其置于顶层0            graphicsContainer.AddElement(element, 0);            //将图像容器装入活动视图中并刷新            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);        }        //--3、在鹰眼视图中通过拖拽改变主视图中地图的显示位置        //是否执行拖拽开关        Boolean moveView = false;        //鼠标按下时        private void axMapControl2_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)        {            moveView = true;        }        //鼠标移动时        private void axMapControl2_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)        {            //判断鼠标是否被按下            if (moveView)            {                IPoint point = new PointClass();                point.PutCoords(e.mapX, e.mapY);                //改变主控件的视图范围                axMapControl1.CenterAt(point);            }        }        //鼠标抬起时        private void axMapControl2_OnMouseUp(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseUpEvent e)        {            moveView = false;        }    }}


热点排行