实例介绍
【实例简介】
【实例截图】
【核心代码】
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.Display; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.ADF; using System.IO; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.SystemUI; namespace 资源环境管理系统 { public partial class Form1 : Form { #region private int flagSelect = 0;//选择标记 private ITOCControl2 m_tocControl=null;//TOC控件 private IMapControl3 m_mapControl = null;//Map控件 private IToolbarMenu m_menuLayer = null;//图层菜单控件 #endregion /// <summary> /// 主窗体构造函数 /// </summary> public Form1() { InitializeComponent(); } /// <summary> /// 主窗体加载事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Load(object sender, EventArgs e) { //创建鹰眼窗口 CreateOverviewSymbol(); //地图控件对应绑定 m_tocControl = (ITOCControl2)axTOCControl1.Object; m_mapControl = (IMapControl3)axMapControl1.Object; //设置关联控件 m_tocControl.SetBuddyControl(m_mapControl); axToolbarControl1.SetBuddyControl(m_mapControl); //打开图层属性表 m_menuLayer = new ToolbarMenuClass(); m_menuLayer.AddItem(new OpenAttributeTableCmd(), 0, 0); //设置关联hook m_menuLayer.SetHook(m_mapControl); } /// <summary> /// 加载地图图层 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e) { IMap pMap;//地图接口 pMap = axMapControl1.Map;//引用地图控件赋值 int i; //循环加载地图图层 for (i = 0; i <= pMap.LayerCount - 1; i ) { axMapControl2.Map.AddLayer(pMap.get_Layer(i)); } //设置图层范围 this.axMapControl2.Extent = this.axMapControl2.FullExtent; } /// <summary> /// 创建鹰眼窗口 /// </summary> private void CreateOverviewSymbol() { //获取IRGBColor接口. IRgbColor color = new RgbColorClass(); //设置颜色属性 color.RGB = 255; //获取线性符号l接口 ILineSymbol outline = new SimpleLineSymbolClass(); //设置线性符号属性 outline.Width = 2; outline.Color = color; //获取填充符号接口 ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); //设置填充符号属性 simpleFillSymbol.Outline = outline; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow; } /// <summary> /// 鼠标移动事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e) { toolStripStatusLabel1.Text = "X:" e.mapX.ToString();//获取地图x坐标 toolStripStatusLabel2.Text = "Y:" e.mapY.ToString();//获取地图y坐标 toolStripStatusLabel3.Text = "地图缩放比例:" Convert.ToInt32(axMapControl1.FullExtent.Height / axMapControl1.Extent.Height * 100) "%";//获取地图缩放比例 } //打开地图事件 private void openFileToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog2 = new OpenFileDialog();//文件选择框 openFileDialog2.Title = "打开地图文档";//设置标题 openFileDialog2.Filter = "地图文档 (*.mxd)|*.mxd";//设置过滤条件 openFileDialog2.ShowDialog();//打开文件选择框 string sFilePath = openFileDialog2.FileName;//获取选择文件路径 if (axMapControl1.CheckMxFile(sFilePath))//验证是否地图文档 { axMapControl1.LoadMxFile(sFilePath, 0, Type.Missing);//加载地图文档 } else { MessageBox.Show(sFilePath " 格式不正确!");//提示错误 return; } } /// <summary> /// 鼠标按下事件,处理选择事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { //制定几何接口 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; IGeometry selectGeo = null; //判断选择标记 if (flagSelect != 0) { //分类出来 switch (flagSelect) { case 1://矩形选择 selectGeo=axMapControl1.TrackRectangle (); axMapControl2.Refresh(); break; case 2://圆形选择 selectGeo = axMapControl1.TrackCircle(); axMapControl2.Refresh(); break; case 3://线性选择 selectGeo = axMapControl1.TrackLine(); axMapControl2.Refresh(); break; default ://清空 flagSelect=0; break; } if (null != selectGeo) { axMapControl1.Map.SelectByShape(selectGeo, null, false); axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); } } } /// <summary> /// 矩形标记事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void rectangleToolStripMenuItem_Click(object sender, EventArgs e) { flagSelect = 1; } /// <summary> /// 圆形标记事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void circleToolStripMenuItem_Click(object sender, EventArgs e) { flagSelect = 2; } /// <summary> /// 线性标记事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lineToolStripMenuItem_Click(object sender, EventArgs e) { flagSelect = 3; } /// <summary> /// 清空事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void clearToolStripMenuItem_Click(object sender, EventArgs e) { //清除选择 //在这里需要特别注意,在清除选择集前必须做一个刷新,否则在视图上看不到清除的效果 IActiveView pActiveView = (IActiveView)(axMapControl1.Map); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, axMapControl1.get_Layer(0), null); axMapControl1.Map.ClearSelection(); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, axMapControl1.get_Layer(0), null); axMapControl2.Refresh(); } //地图内容控件右键菜单 private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) { if (e.button == 1) { #region "左键点击图例符号,弹出符号选择对话框" IBasicMap map = new MapClass(); ILayer layer = new FeatureLayerClass(); object other = new object(); object index = new object(); esriTOCControlItem item = new esriTOCControlItem(); //定义点击类别 axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); //查询要素接口 if (layer == null) return; IFeatureLayer featureLayer = layer as IFeatureLayer; if (featureLayer == null) return; IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer; ILegendClass legendClass = new LegendClassClass(); ISymbol symbol = null; if (other is ILegendGroup && (int)index != -1) { legendClass = ((ILegendGroup)other).get_Class((int)index); symbol = legendClass.Symbol; } if (symbol == null) return; symbol = GetSymbolByControl(symbol); if (symbol == null) return; legendClass.Symbol = symbol; this.Activate(); //监听内容改变事件 axMapControl1.ActiveView.ContentsChanged(); //刷新展示 axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null); axMapControl2.Refresh(esriViewDrawPhase.esriViewGeography, null, null); axTOCControl1.Update(); #endregion } if (e.button == 2) { esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone; IBasicMap map = null; ILayer layer = null; object other = null; object index = null; //定义选择项类别 m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); //确保选中 if (item == esriTOCControlItem.esriTOCControlItemMap) m_tocControl.SelectItem(map, null); else m_tocControl.SelectItem(layer, null); //设置图层自定义属性 m_mapControl.CustomProperty = layer; if (item == esriTOCControlItem.esriTOCControlItemLayer) m_menuLayer.PopupMenu(e.x, e.y, m_tocControl.hWnd); } } /// <summary> /// 获取样式符号,展示图层符号配置窗口 /// </summary> /// <param name="symbolType"></param> /// <returns></returns> private ISymbol GetSymbolByControl(ISymbol symbolType) { ISymbol symbol = null; IStyleGalleryItem styleGalleryItem = null; esriSymbologyStyleClass styleClass = esriSymbologyStyleClass.esriStyleClassMarkerSymbols; if (symbolType is IMarkerSymbol) { styleClass = esriSymbologyStyleClass.esriStyleClassMarkerSymbols; } if (symbolType is ILineSymbol) { styleClass = esriSymbologyStyleClass.esriStyleClassLineSymbols; } if (symbolType is IFillSymbol) { styleClass = esriSymbologyStyleClass.esriStyleClassFillSymbols; } GetSymbolByControlForm symbolForm = new GetSymbolByControlForm(styleClass); symbolForm.ShowDialog(); styleGalleryItem = symbolForm.m_styleGalleryItem; if (styleGalleryItem == null) return null; symbol = styleGalleryItem.Item as ISymbol; symbolForm.Dispose(); this.Activate(); return symbol; } /// <summary> /// 属性选择事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void selectByAttributesToolStripMenuItem_Click(object sender, EventArgs e) { ICommand command = new AttributeQueryCmd(); command.OnCreate(m_mapControl.Object); command.OnClick(); } } }
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论