码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2015-06-29 23:49:26      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

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 鹰眼功能完结

放效果图一张:

技术分享

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

标签:

原文地址:http://www.cnblogs.com/smilepeter/p/4608875.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!