标签:sem png cti 中移动 .text strip null comm amp
灾前灾后对比功能是GIS软件中常用的功能之一,指利用多时相获取的覆盖同一地表区域的遥感影像及其它辅助数据来确定和分析地表变化。它利用计算机图像处理系统,对不同时段目标或现象状态的变化进行识别、分析;它能确定一定时间间隔内地物或现象的变化,并提供地物的空间分布及其变化的定性与定量信息。现在呢,具体介绍下基于我们PIE SDK是如何实现这基本工具灾前灾后对比功能的基本实现。
【在前灾后功能界面图】
要实现灾前灾后对比功能主要就是通过两个mapControl控件,灾前地图控件是mapControl_left,灾后地图控件是mapControl_right,实现关键点有四点:1、如何给两个控件添加常用控件;2、如何使两个控件的显示范围保持一致;3、如何在状态栏中显示地图坐标及屏幕坐标;4、如何给两个控件右上角添加元素。
添加两个toolStrip,分别在toolStrip上添加六个button,分别给六个button添加单击事件(本文以放大控件为例)。
1 /// <summary> 2 /// mapControl_left地图放大事件 3 /// </summary> 4 /// <param name="sender">事件触发器</param> 5 /// <param name="e">事件参数</param> 6 private void toolStripButton_zoomInLeft_Click(object sender, EventArgs e) 7 { 8 ITool tool = new PIE.Controls.MapZoomInTool(); 9 (tool as ICommand).OnCreate(mapControl_left); 10 mapControl_left.CurrentTool = tool; 11 }
使两个控件的显示范围保持一致主要是当灾前地图的范围发生变化的时候,灾后地图的范围跟着变化。
而实现灾前灾后对比功能,主要发生在灾前地图和灾后地图控件相应响应事件中,即mapControl_left和mapControl_right的OnExtentUpdated事件。当灾前地图mapControl_left范围发生变化时,会触发OnExtentUpdated事件,那么灾后地图的范围跟着变化。
1 /// <summary> 2 /// mapControl_left范围变化事件 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="sizeChanged"></param> 6 /// <param name="newEnvelope"></param> 7 void mapControl_left_OnExtentUpdated(object sender, bool sizeChanged, IEnvelope newEnvelope) 8 { 9 if (mapControl_left.GetLayer(0) != null && mapControl_right.GetLayer(0) != null && m_Lock == false) 10 { 11 m_Lock = true; 12 mapControl_right.Extent = mapControl_left.Extent; 13 mapControl_right.ActiveView.PartialRefresh(ViewDrawPhaseType.ViewAll); 14 m_Lock = false; 15 } 16 }
在状态栏中显示地图坐标及屏幕坐标主要是当鼠标在地图控件中移动时,在状态栏中显示鼠标所在位置的地图坐标及屏幕坐标。首先,添加一个statusStrip,在statusStrip上添加一个StatusLabel。
而实现在状态栏中显示地图坐标及屏幕坐标功能,主要发生在灾前地图和灾后地图控件相应响应事件中,即mapControl_left和mapControl_right的MouseMove事件。当鼠标在地图控件中移动时,会触发MouseMove事件,那么状态栏中显示鼠标所在位置的地图坐标及屏幕坐标。
1 /// <summary> 2 /// mapControl_left鼠标移动事件 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 6 private void mapControl_left_MouseMove(object sender, MouseEventArgs e) 7 { 8 toolStripStatusLabel_Coo.Text = "地图坐标:" + Math.Round(mapControl_left.FocusMap.ToMapPoint(e.Location).X, 4) + "," + Math.Round(mapControl_left.FocusMap.ToMapPoint(e.Location).Y, 4) + " 屏幕坐标:" + e.X + "," + e.Y; 9 }
如何给两个控件右上角添加元素主要是在两个地图控件右上角始终显示元素。
首先,当窗体加载(即控件中没有元素)时,要在控件中绘制元素。
1 /// <summary> 2 /// UserControl_Disaster加载事件 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 6 private void UserControl_Disaster_Load(object sender, EventArgs e) 7 { 8 mapControl_left.OnExtentUpdated += mapControl_left_OnExtentUpdated; 9 mapControl_right.OnExtentUpdated += mapControl_right_OnExtentUpdated; 10 DrawTwoElement(); 11 mapControl_left.ActiveView.PartialRefresh(ViewDrawPhaseType.ViewAll); 12 mapControl_right.ActiveView.PartialRefresh(ViewDrawPhaseType.ViewAll); 13 toolStripStatusLabel_Coo.Alignment = ToolStripItemAlignment.Right; 14 }
而控件中已经存在元素时,当灾前地图mapControl_left或灾后地图mapControl_right范围发生变化时,只需修改元素的位置即可。实现修改元素的位置功能,主要发生在灾前地图和灾后地图控件相应响应事件中,即mapControl_left和mapControl_right的OnExtentUpdated事件。
1 /// <summary> 2 /// mapControl_left范围变化事件 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="sizeChanged"></param> 6 /// <param name="newEnvelope"></param> 7 void mapControl_left_OnExtentUpdated(object sender, bool sizeChanged, IEnvelope newEnvelope) 8 { 9 if (mapControl_left.GetLayer(0) != null && mapControl_right.GetLayer(0) != null && m_Lock == false) 10 { 11 DrawTwoElement(); 12 } 13 } 14 15 /// <summary> 16 /// 绘制两个mapcontrol中元素函数 17 /// </summary> 18 private void DrawTwoElement() 19 { 20 DrawElement(mapControl_left,m_LeftCaption); 21 DrawElement(mapControl_right, m_RightCaption); 22 } 23 /// <summary> 24 /// 绘制一个mapcontrol中元素函数 25 /// </summary> 26 private void DrawElement(MapControl mapcontrol, String Caption) 27 { 28 if (mapcontrol == null||Caption==null) return; 29 double xCoordinate = mapcontrol.Extent.XMax; 30 double yCoordinate = mapcontrol.Extent.YMax; 31 32 IPoint point = new PIE.Geometry.Point(); 33 point.PutCoords(xCoordinate, yCoordinate); 34 (point as IGeometry).SpatialReference = mapcontrol.FocusMap.SpatialReference; 35 36 if (mapcontrol.ActiveView.GraphicsContainer.ElementCount == 0) 37 { 38 ITextSymbol textSymbol = new TextSymbol(); 39 textSymbol.Size = 36; 40 textSymbol.Color = System.Drawing.Color.Red; 41 textSymbol.Angle = 0.6; 42 textSymbol.Font = new System.Drawing.Font("Times New Roman", 100, FontStyle.Bold); 43 textSymbol.Alignment = TextAlignmentType.AlignRight; 44 45 ITextElement textElement = new TextElement(); 46 textElement.Geometry = point as IGeometry; 47 textElement.Symbol = textSymbol; 48 textElement.Text = Caption; 49 textElement.Name = "caption"; 50 mapcontrol.ActiveView.GraphicsContainer.AddElement(textElement); 51 } 52 else 53 { 54 IList<IElement> list = mapcontrol.ActiveView.GraphicsContainer.GetAllElements(); 55 foreach(Element element in list) 56 { 57 if(element.Name=="caption") 58 { 59 ITextElement textElement = element as ITextElement; 60 textElement.Geometry = point as IGeometry; 61 } 62 } 63 } 64 }
标签:sem png cti 中移动 .text strip null comm amp
原文地址:https://www.cnblogs.com/PIESat/p/10271741.html