arcengine突击2——鹰眼实现

分析:

主视图事件,当地图加载时,鸟瞰视图也随之加载地图;当主视图显示范围发生变化,鸟瞰视图框框(框框代表对主视图的鸟瞰)发生变化。

鸟瞰视图事件,当按住鼠标左键移动、鼠标单击时捕捉主视图范围,更新框框

添加liscen控件、两个map控件、toc控件、toolbar控件;在toc、toolbar属性页的buddy中设置绑定map1;在toolbar属性页中添加文件打开open。

点击设计视图中的两个地图控件,在属性表中的事件中绑定编写以下事件:

Map1_onMapReplaced:

如果视图1的图层数大于0,清空视图2已有图层,遍历视图1中各图层并添加到视图2中。设置视图2的空间参考系、显示范围,并刷新显示视图2的活动窗口。

Map1_onExtentUpdated:

       新范围获取:

转换事件源新包络线为包络线,转换视图2的地图为图形容器,转换图形容器为活动视图

删除图形容器已有元素

红框线设置

新建矩形元素,转换矩形元素为元素,设置元素形状为包络线;

新建颜色对象,设置rgb值,不透明

新建线符号对象,颜色为颜色对象

新建填充符号对象,调整颜色透明度,颜色为颜色对象,填充轮廓为线符号对象

       红框线生成

              转换元素为填充形状元素对象,设置符号为填充符号对象。

              在图形容器中添加填充形状元素

              刷新活动视图

Map2_onMouseMove:

       如果是左键,生成点,以鼠标事件源的地图坐标赋值点坐标,将map1的中心移到点处,刷新map1的活动视图

Map2_onMouseDown:

       如果是左键,生成点,以鼠标事件源的地图坐标赋值点坐标,将map1的中心移到点处,刷新map1的活动视图

       如果是右键,新建包络线为map2的矩形轨迹,map1的范围为包络线,刷新map1

private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e)
        {
            if (axMapControl1.LayerCount > 0)
            {
                axMapControl2.ClearLayers();
                for (int i = 0; i < axMapControl1.Map.LayerCount; i++)
                {
                    axMapControl2.AddLayer(axMapControl1.get_Layer(i));
                }
                axMapControl2.SpatialReference = axMapControl1.SpatialReference;
                axMapControl2.Extent = axMapControl2.FullExtent;
                axMapControl2.ActiveView.Refresh();
            }
        }

        private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
        {
            IEnvelope pEnvelope = e.newEnvelope as IEnvelope;
            IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer;
            IActiveView pActiveView = pGraphicsContainer as IActiveView;

            pGraphicsContainer.DeleteAllElements();

            IRectangleElement pRectangleElement = new RectangleElementClass();
            IElement pElement = pRectangleElement as IElement;
            pElement.Geometry = pEnvelope;

            IRgbColor pColor = new RgbColorClass();
            pColor.Red = 255;
            pColor.Green = 0;
            pColor.Blue = 0;
            pColor.Transparency = 255;

            ILineSymbol pLine = new SimpleLineSymbolClass();
            pLine.Color = pColor;

            pColor.Transparency = 0;

            IFillSymbol pFill = new SimpleFillSymbolClass();
            pFill.Color = pColor;
            pFill.Outline = pLine;

            IFillShapeElement pFillShapeElement = pElement as IFillShapeElement;
            pFillShapeElement.Symbol = pFill;
            pGraphicsContainer.AddElement((IElement)pFillShapeElement, 0);
            pActiveView.Refresh();
        }

        private void axMapControl2_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            if (axMapControl2.LayerCount > 0)
            {
                if (e.button == 1)
                {
                    IPoint point = new PointClass();
                    point.PutCoords(e.mapX, e.mapY);
                    axMapControl1.CenterAt(point);
                    axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                }
                else if (e.button == 2)
                {
                    IEnvelope pEnv = axMapControl2.TrackRectangle();
                    axMapControl1.Extent = pEnv;
                    axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                }
            }
        }

        private void axMapControl2_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
        {
            if (axMapControl2.LayerCount > 0)
            {
                if (e.button == 1)
                {
                    IPoint point = new PointClass();
                    point.PutCoords(e.mapX, e.mapY);
                    axMapControl1.CenterAt(point);
                    axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                }
            }
        }

猜你喜欢

转载自blog.csdn.net/nominior/article/details/84593672