C#+arcengine10.0+SP5实现鹰眼(加载的是mdb数据库中的数据)

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.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesRaster;
using DevComponents.DotNetBar;

using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Display;
  private void btAddMdb_Click_1(object sender, EventArgs e)     //添加mdb数据库打开数据
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = " Personal Geodatabase(*.mdb)|*.mdb|All Files(*.*)|*.* ";
            dlg.Title = " Open PersonGeodatabase file ";
            if (dlg.ShowDialog() != DialogResult.OK) return;
            commonfun.load_Mdb(dlg.FileName, axMap);
            AddLayerToOverViewMap();   //加入地图到鹰眼里
            axMap.Refresh();
        }

  

 private void axMap_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
        {        
            #region 添加鹰眼   载入地图到鹰眼控件
            AddLayerToOverViewMap();
            #endregion                   
        }
  #region 鹰眼功能
        /// <summary>
        /// 把地图加到鹰眼里的方法,
///该段代码摘自http://www.cnblogs.com/zya-gis/archive/2009/04/17/1438033.html,非常好用,解决了我鹰眼一直不能显示的问题
/// </summary> private void AddLayerToOverViewMap() { axMapSmall.ClearLayers(); for (int i = 0; i < axMap.LayerCount; i++) { IObjectCopy objectcopy = new ObjectCopyClass(); object toCopyLayer = axMap.get_Layer(i); object copiedLayer = objectcopy.Copy(toCopyLayer); ILayer C = (new FeatureLayerClass()) as ILayer; object toOverwriteLayer = C; objectcopy.Overwrite(copiedLayer, ref toOverwriteLayer); axMapSmall.AddLayer(C, i); } } private void axMap_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e) //绘制鹰眼矩形框 { try { //得到范围 IEnvelope pEnv = e.newEnvelope as IEnvelope; IGraphicsContainer pGraphicsContainer = axMapSmall.Map as IGraphicsContainer; IActiveView pActiveView = pGraphicsContainer as IActiveView; //在绘制新的矩形框前,清楚、清除Map对象中的任何图形元素 pGraphicsContainer.DeleteAllElements(); IRectangleElement pRectangleEle = new RectangleElementClass(); IElement pEle = pRectangleEle as IElement; pEle.Geometry = pEnv; IRgbColor pColor = new RgbColorClass(); pColor.RGB = 255; pColor.Transparency = 255; //产生一个线符号对象 ILineSymbol pOutLine = new SimpleLineSymbolClass(); pOutLine.Width = 1; pOutLine.Color = pColor; //设置颜色属性 pColor.RGB = 255; pColor.Transparency = 0; //设置填充符号的属性 IFillSymbol pFillsymbol = new SimpleFillSymbolClass(); pFillsymbol.Color = pColor; pFillsymbol.Outline = pOutLine; IFillShapeElement pFillshapEle; pFillshapEle = pEle as IFillShapeElement; pFillshapEle.Symbol = pFillsymbol; pEle = pFillshapEle as IElement; pGraphicsContainer.AddElement(pEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch (Exception ey) { } } private void axMapSmall_OnMouseDown(object sender, AxESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e) //鹰眼与主 Map 控件互动 { if (this.axMapSmall.Map.LayerCount != 0) { // 按下鼠标左键移动矩形框 if (e.button == 1) { IPoint pPoint = new PointClass(); pPoint.PutCoords(e.mapX, e.mapY); IEnvelope pEnvelope = this.axMap.Extent; pEnvelope.CenterAt(pPoint); this.axMap.Extent = pEnvelope; this.axMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } // 按下鼠标右键绘制矩形框 else if (e.button == 2) { IEnvelope pEnvelop = this.axMapSmall.TrackRectangle(); this.axMap.Extent = pEnvelop; this.axMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } } } private void axMapSmall_OnMouseMove(object sender, AxESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e) //按下鼠标左键的时候移动矩形框,同时也改变主的图控件的显示范围 { // 如果不是左键按下就直接返回 if (e.button != 1) return; IPoint pPoint = new PointClass(); pPoint.PutCoords(e.mapX, e.mapY); this.axMap.CenterAt(pPoint); this.axMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } #endregion 鹰眼功能完结

放效果图一张:

转载于:https://www.cnblogs.com/smilepeter/p/4608875.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值