/// <summary> /// 鼠标移动时运行 /// </summary> /// <param name="movePT">鼠标地图点</param> public void OnMouseMoveRun(IPoint movePT) { if (polygonFeedback != null) { polygonFeedback.MoveTo(movePT); } // 点集合 IPointCollection pointColTemp = new Polygon(); for (int i = 0; i < pointCollection.PointCount; i++) { pointColTemp.AddPoint(pointCollection.get_Point(i), Type.Missing, Type.Missing); } // 添加当前点 pointColTemp.AddPoint(movePT); if (pointColTemp.PointCount < 3) { return; } // 获得图形 IPolygon polygon = pointColTemp as IPolygon; if (polygon != null) { polygon.Close(); IGeometry geo = polygon as IGeometry; ITopologicalOperator topo = geo as ITopologicalOperator; topo.Simplify(); geo.Project(mapControl.SpatialReference); // 获得面积 IArea area = geo as IArea; totalArea = area.Area; } }
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { switch (m_sketchshape) { case "polygon": { if (m_NewPolygonFeedback != null) { IPoint iPoint = new PointClass(); iPoint = m_MapCtrls.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); m_NewPolygonFeedback.MoveTo(iPoint); } } break; case "rectangle": { IScreenDisplay iSDisplay = m_MapCtrls.ActiveView.ScreenDisplay; IPoint newPoint = new PointClass(); newPoint = iSDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); if (m_RecFeedback != null) { m_RecFeedback.MoveTo(newPoint); } } break; } }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { if (m_polygonFeedback != null) { IPoint cursorPoint = m_screenDisplay.DisplayTransformation.ToMapPoint(X, Y); m_polygonFeedback.MoveTo(cursorPoint); } }
//鼠标移动, 将工具也移动到点的位置 public override void OnMouseMove(int Button, int Shift, int X, int Y) { base.OnMouseMove(Button, Shift, X, Y); IPoint pPoint = m_MapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); m_pNewPolygonFeedback.MoveTo(pPoint); }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { if (m_pNewPolygonFeedback != null) { IPoint pPnt; pPnt = (IPoint)m_pScrD.DisplayTransformation.ToMapPoint(X, Y); m_pNewPolygonFeedback.MoveTo(pPnt); } }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { if (_startPoint != null) { IPoint movePoint = (myHook.FocusMap as IActiveView).ScreenDisplay. DisplayTransformation.ToMapPoint(X, Y); _polyFeedback.MoveTo(movePoint); } }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { IPoint pt = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); pt = GIS.GraphicEdit.SnapSetting.getSnapPoint(pt); if (m_NewPolygonFeedback == null) { return; } m_NewPolygonFeedback.MoveTo(pt); if (m_ptCollection.PointCount == 0) { return; } double d_Total = 0; double d_segment = 0; double d_Area = 0;//20140219 lyf IPoint lastPt = m_ptCollection.get_Point(m_ptCollection.PointCount - 1); ILine line = new LineClass(); line.PutCoords(lastPt, pt); //节距离 d_segment = line.Length; m_frmMeasureResult.Segment = d_segment; ///20140219 lyf 当前点和起始点距离,计算周长用 IPoint firstPt = m_ptCollection.get_Point(0); ILine tempLastLine = new LineClass(); tempLastLine.PutCoords(pt, firstPt); try { IPolyline polyline = m_ptCollection as IPolyline; if (polyline.IsEmpty) { d_Total = d_segment; d_Area = 0; } else { d_Total = polyline.Length + d_segment + tempLastLine.Length; d_Area = CaculateArea(pt); } } catch { } //赋值给总长度 m_frmMeasureResult.Total = d_Total; m_frmMeasureResult.Area = d_Area; m_frmMeasureResult.PolygonResultChange(); }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { // TODO: Add AreaPrintMapClass.OnMouseMove implementation if (m_NewPolygonFeedback != null) { IPoint pPoint; pPoint = (IPoint)m_ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); m_NewPolygonFeedback.MoveTo(pPoint); } }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { // TODO: Add ToolAddTinPlane.OnMouseMove implementation IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2; if (mNewPolygonFeedback != null && pMapCtr != null) { IPoint mapPoint = pMapCtr.ToMapPoint(X, Y); mNewPolygonFeedback.MoveTo(mapPoint); } }
private void OnOnMouseMove(int button, int shift, int i, int i1, double mapX, double mapY) { if (_polygonFeedback == null) { return; } IPoint point = new PointClass(); point.PutCoords(mapX, mapY); _polygonFeedback.MoveTo(point); }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { IPoint pPt = m_ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); //MoveTo方法继承自IDisplayFeedback接口的定义 if (pPolygonFeedback != null) { pPolygonFeedback.MoveTo(pPt); } m_pPoint = m_ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { if (m_hookHelper != null) { IPoint pPoint; pPoint = m_pScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); m_blnSnap = false; if (ClsDeclare.g_blnSnap == true) { m_pSnapPoint = ClsMeasureSnap.MeasureSnapPoint(ref pPoint); if (m_pSnapPoint != null) { m_blnSnap = true; } else { m_blnSnap = false; } } if (m_pNewPolygonFeedback != null) { if (m_blnSnap == true) { m_pNewPolygonFeedback.MoveTo(m_pSnapPoint); } else { m_pNewPolygonFeedback.MoveTo(pPoint); } } } else if (m_sceneHookHelper != null) { } else if (m_globeHookHelper != null) { } }
/// <summary> /// 移动鼠标位置,动态改变折线或多边形最后节点的位置, /// 重新计算各个测量值,建议在Map的MouseMove事件中调用, /// 并提取当前的测量结果进行显示 /// </summary> /// <param name="point">终点</param> public void MoveTo(IPoint point) { if (_eMeasureType == EMeasureType.Distance || _eMeasureType == EMeasureType.Angle) { _newLineFeedback.MoveTo(point); CalculateLength(point); CalculateDirection(point); CalculateAngle(point); } else if (_eMeasureType == EMeasureType.Area) { _newPolygonFeedback.MoveTo(point); CalculateArea(point); } }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { // TODO: Add ToolRasterEdit.OnMouseMove implementation IMapControl3 pMapCtrl = ClsGlobal.GetMapControl(m_hookHelper); if (pMapCtrl == null) { return; } IPoint pPoint = pMapCtrl.ToMapPoint(X, Y); if (m_NewPolygonFeedback != null) { m_NewPolygonFeedback.MoveTo(pPoint); } }
/// <summary> /// 鼠标移动,在此动态在m_GeoMeasure中加入鼠标现在的点进行动态量测 /// </summary> /// <param name="Button"></param> /// <param name="Shift"></param> /// <param name="X"></param> /// <param name="Y"></param> public override void OnMouseMove(int Button, int Shift, int X, int Y) { // TODO: Add ToolMeasureArea.OnMouseMove implementation if (this.m_GeoMeasure == null) { return; } IActiveView ipAV = this.m_hookHelper.ActiveView; ///////////生成新点/////////////// IPoint ipPt = new PointClass(); ipPt = ipAV.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); SnapPoint(ipPt); if (m_pNewPolygonFeed != null) { m_pNewPolygonFeed.MoveTo(ipPt); } /* * ///////生成新图形///////// * IClone ipClone = this.m_GeoMeasure as IClone; * IGeometry ipGeo = ipClone.Clone() as IGeometry; * object obj = Type.Missing; * * IGeometryCollection ipGeoCol = ipGeo as IGeometryCollection; * ISegmentCollection ipSelCol = ipGeoCol.get_Geometry(0) as ISegmentCollection; * ipSelCol.RemoveSegments(ipSelCol.SegmentCount - 1, 1, false); * ILine ipLine = new LineClass(); * ipLine.PutCoords(ipSelCol.get_Segment(ipSelCol.SegmentCount - 1).ToPoint, ipPt); * ISegment ipSeg = ipLine as ISegment; * ipSelCol.AddSegment(ipSeg, ref obj, ref obj); * ipLine = new LineClass(); * ipLine.PutCoords(ipPt, ipSelCol.get_Segment(0).FromPoint); * ipSeg = ipLine as ISegment; * ipSelCol.AddSegment(ipSeg, ref obj, ref obj); * * ////////显示///////////// * this.m_Element.Geometry = ipGeo; * //局部刷新 * ipAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, ipGeo, null); * //ipAV.Refresh(); */ }
public void OnMouseMove(int button, int shift, int x, int y) { IPoint pPt = m_activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); if (m_EngineEditLayers == null) return; //获取编辑目标图层 IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer; if (pFeatLyr == null) return; IFeatureClass pFeatCls = pFeatLyr.FeatureClass; if (pFeatCls == null) return; switch (pFeatCls.ShapeType) { case esriGeometryType.esriGeometryPolyline: if (m_newLineFeedBack != null) m_newLineFeedBack.MoveTo(pPt); break; case esriGeometryType.esriGeometryPolygon: if (m_newPolyFeedBack != null) m_newPolyFeedBack.MoveTo(pPt); break; } }
public override void OnKeyUp(int keyCode, int Shift) { if (Shift != 2 && keyCode != 90) { return; } if (m_pNewPolygonFeedback == null) { return; } IPolygon pPolygon = m_pNewPolygonFeedback.Stop(); m_pNewPolygonFeedback = null; if (pPolygon == null) { return; } IPointCollection pntCol = pPolygon as IPointCollection; IRgbColor pRGB = new RgbColorClass(); ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pRGB.Red = 15; pRGB.Blue = 15; pRGB.Green = 0; pSimpleFillSymbol.Color = pRGB; pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; m_pNewPolygonFeedback = new NewPolygonFeedbackClass(); m_pNewPolygonFeedback.Symbol = pSimpleFillSymbol as ISymbol; m_pNewPolygonFeedback.Display = m_MapControl.ActiveView.ScreenDisplay; m_pNewPolygonFeedback.Start(pntCol.get_Point(0)); for (int i = 1; i < pntCol.PointCount - 2; i++) { m_pNewPolygonFeedback.AddPoint(pntCol.get_Point(i)); } m_pNewPolygonFeedback.MoveTo(pntCol.get_Point(pntCol.PointCount - 1)); }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { IFeatureLayer m_FeatureLayer = (IFeatureLayer)CreateShape.m_CurrentLayer;; if (m_FeatureLayer.FeatureClass == null) { return; } // 移动鼠标形成线、面的节点 IActiveView m_ActiveView = m_AxMapControl.ActiveView; IPoint pMovePoint = m_ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); if (m_pNewLineFeedback != null) { m_pNewLineFeedback.MoveTo(pMovePoint); } else if (m_pPlygonFeadback != null) { m_pPlygonFeadback.MoveTo(pMovePoint); } }
public void OnMouseMove(int button, int shift, int x, int y) { IPoint point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); if (engineEditLayers == null) { return; } //获取编辑目标图层 IFeatureLayer featureLayer = engineEditLayers.TargetLayer; if (featureLayer == null) { return; } IFeatureClass featureClass = featureLayer.FeatureClass; if (featureClass == null) { return; } switch (featureClass.ShapeType) { case esriGeometryType.esriGeometryPolyline: if (newLineFeedback != null) { newLineFeedback.MoveTo(point); } break; case esriGeometryType.esriGeometryPolygon: if (newLineFeedback != null) { newPolygonFeedback.MoveTo(point); } break; } }
public override void OnMouseMove(int Button, int Shift, int X, int Y) { IPoint pPt = m_activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); if (m_EngineEditLayers == null) { return; } //获取编辑目标图层 IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer; if (pFeatLyr == null) { return; } IFeatureClass pFeatCls = pFeatLyr.FeatureClass; if (pFeatCls == null) { return; } switch (pFeatCls.ShapeType) { case esriGeometryType.esriGeometryPolyline: if (m_newLineFeedback != null) { m_newLineFeedback.MoveTo(pPt); } break; case esriGeometryType.esriGeometryPolygon: if (m_newPolygonFeedback != null) { m_newPolygonFeedback.MoveTo(pPt); } break; } }
private void axMapcontrol_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { sMapunits = GetMapunits(this.axMapcontrol.Map.MapUnits); this.barCoortxt.Text = string.Format("当前坐标:X={0:#.###} Y={1:#.###} {2}", e.mapX, e.mapY, sMapunits); movepnt = new PointClass(); movepnt.PutCoords(e.mapX, e.mapY); switch (pMouseOperate) { case "MeasureLength": if (m_newline != null && movepnt != null) { m_newline.MoveTo(movepnt); //计算两点距离 double deltaX = 0; double deltaY = 0; deltaX = movepnt.X - Dwnpoint.X; deltaY = movepnt.Y - Dwnpoint.Y; SegmentLength = Math.Round(Math.Sqrt(deltaX * deltaX + deltaY * deltaY)); TotalLength = TotalLength + SegmentLength; if (frmMeasureResult != null) { //绑定事件 ShowResultEvent += new showResult(frmMeasureResult.showResult); ShowResultEvent(new double[] { SegmentLength, TotalLength }, sMapunits, pMouseOperate); TotalLength = TotalLength - SegmentLength; //鼠标移动到新点重新开始算 } } break; case "MeasureArea": if (m_newpolygon != null && Area_Pocoll != null) { m_newpolygon.MoveTo(movepnt); IPointCollection pocoll = new PolygonClass(); IGeometry pGeo = null; IPolygon polygon = null; ITopologicalOperator topo = null; for (int i = 0; i < Area_Pocoll.PointCount; i++) { pocoll.AddPoint(Area_Pocoll.get_Point(i), missing, missing); } if (movepnt == null || movepnt.IsEmpty) { return; } pocoll.AddPoint(movepnt, missing, missing); if (pocoll.PointCount < 3) { return; } polygon = pocoll as IPolygon; if (polygon == null) { return; } //多边形闭合 polygon.Close(); pGeo = polygon as IGeometry; topo = pGeo as ITopologicalOperator; //使几何图形的拓扑正确 topo.Simplify(); pGeo.Project(this.axMapcontrol.SpatialReference); IArea area = pGeo as IArea; if (frmMeasureResult != null && !frmMeasureResult.IsDisposed) { ShowResultEvent += new showResult(frmMeasureResult.showResult); ShowResultEvent(new double[] { area.Area, polygon.Length }, sMapunits, pMouseOperate); } } break; } }
public void frmMove(ref IPoint pPoint, ref INewPolygonFeedback m_FeedbackPolygon) { if (tbtnArea.Checked == true) { IPoint pPnt = pPoint; m_CurPoint = pPnt; if (m_FeedbackPolygon != null) { m_FeedbackPolygon.MoveTo(pPnt); double MoveArea = 0.0; double MoveLength = 0.0; double tempLegth = 0.0; IPoint LastPoint = pCollection.get_Point(pCollection.PointCount - 1); IPoint CurPoint = m_CurPoint; IPoint FirstPoint = pCollection.get_Point(0); SegAreaLength = Math.Sqrt(Math.Pow((LastPoint.X - CurPoint.X), 2) + Math.Pow((LastPoint.Y - CurPoint.Y), 2)); tempLegth = Math.Sqrt(Math.Pow((CurPoint.X - FirstPoint.X), 2) + Math.Pow((CurPoint.Y - FirstPoint.Y), 2)); MoveLength = TotalAreaLength + SegAreaLength + tempLegth; double CntMoveLength = CntUnit.ConvertUnits(MoveLength, inUnit.pUnit, outUnit.pUnit); double CntSegAreaLength = CntUnit.ConvertUnits(SegAreaLength, inUnit.pUnit, outUnit.pUnit); MoveArea = CaculateArea(pPnt); double CntMoveArea; string AreaUnitMess; CntMoveArea = ConvertToArea(MoveArea, inAreaUnit.UnitName, outAreaUnit.UnitName); if (outAreaUnit.UnitName == "Unkown Units") { AreaUnitMess = outAreaUnit.UnitName; } else { AreaUnitMess = "Square " + outAreaUnit.UnitName; } m_SegLen.value = CntSegAreaLength; m_SegLen.units = outUnit.pUnit; m_TotLen.value = CntMoveLength; m_TotLen.units = outUnit.pUnit; m_Area.value = CntMoveArea; m_Area.units = outAreaUnit.pUnit; CntMoveLength = Math.Round(CntMoveLength, 6); CntMoveArea = Math.Round(CntMoveArea, 6); CntSegAreaLength = Math.Round(CntSegAreaLength, 6); double tempSumPeri = SumPerimeters + CntMoveLength; double tempSumAreas = SumAreas + CntMoveArea; UnitSumPeri = tempSumPeri; UnitSumArea = tempSumAreas; txtMessage.Text = "测量面" + "\r\n线段长是" + CntSegAreaLength + outUnit.UnitName + "\r\n周长是:" + CntMoveLength + outUnit.UnitName + "\r\n面积是:" + CntMoveArea + AreaUnitMess; if (tbtnSum.Checked == true) { txtMessage.Text += "\r\n" + "\r\n周长长度之和是:" + tempSumPeri + outUnit.UnitName + "\r\n面积之和是:" + tempSumAreas + AreaUnitMess; } } } }
public void frmMove(ref IPoint pPoint, ref INewPolygonFeedback m_FeedbackPolygon) { if (tbtnArea.Checked == true) { IPoint pPnt = pPoint; m_CurPoint = pPnt; if (m_FeedbackPolygon != null) { m_FeedbackPolygon.MoveTo(pPnt); double MoveArea = 0.0; double MoveLength = 0.0; double tempLegth = 0.0; IPoint LastPoint = pCollection.get_Point(pCollection.PointCount - 1); IPoint CurPoint = m_CurPoint; IPoint FirstPoint = pCollection.get_Point(0); SegAreaLength = Math.Sqrt(Math.Pow((LastPoint.X - CurPoint.X), 2) + Math.Pow((LastPoint.Y - CurPoint.Y), 2)); tempLegth = Math.Sqrt(Math.Pow((CurPoint.X - FirstPoint.X), 2) + Math.Pow((CurPoint.Y - FirstPoint.Y), 2)); MoveLength = TotalAreaLength + SegAreaLength + tempLegth; double CntMoveLength = CntUnit.ConvertUnits(MoveLength, inUnit.pUnit, outUnit.pUnit); double CntSegAreaLength = CntUnit.ConvertUnits(SegAreaLength, inUnit.pUnit, outUnit.pUnit); MoveArea = CaculateArea(pPnt); double CntMoveArea; string AreaUnitMess; CntMoveArea=ConvertToArea( MoveArea, inAreaUnit.UnitName , outAreaUnit.UnitName); if (outAreaUnit.UnitName == "Unkown Units") AreaUnitMess = outAreaUnit.UnitName; else AreaUnitMess = "Square " + outAreaUnit.UnitName; m_SegLen.value = CntSegAreaLength; m_SegLen.units = outUnit.pUnit; m_TotLen.value = CntMoveLength; m_TotLen.units = outUnit.pUnit; m_Area.value = CntMoveArea; m_Area.units = outAreaUnit.pUnit; CntMoveLength = Math.Round(CntMoveLength, 6); CntMoveArea = Math.Round(CntMoveArea, 6); CntSegAreaLength = Math.Round(CntSegAreaLength, 6); double tempSumPeri = SumPerimeters + CntMoveLength; double tempSumAreas = SumAreas + CntMoveArea; UnitSumPeri = tempSumPeri; UnitSumArea = tempSumAreas; txtMessage.Text ="测量面" +"\r\n线段长是" + CntSegAreaLength + outUnit.UnitName + "\r\n周长是:" +CntMoveLength + outUnit.UnitName + "\r\n面积是:" + CntMoveArea + AreaUnitMess; if (tbtnSum.Checked == true) txtMessage.Text += "\r\n" + "\r\n周长长度之和是:" +tempSumPeri+ outUnit.UnitName + "\r\n面积之和是:" + tempSumAreas+ AreaUnitMess; } } }
/// <summary> /// MainMapControl鼠标移动事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainMapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { sMapUnits = GetMapUnit(MainMapControl.Map.MapUnits); toolStripStatusLabel1.Text = String.Format("当前坐标:X = {0:#.###} Y = {1:#.###} {2}", e.mapX, e.mapY, sMapUnits); pMovePt = (MainMapControl.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); switch (pMouseOperate) { case "MeasureLength": if (pNewLineFeedback != null) { pNewLineFeedback.MoveTo(pMovePt); } double deltaX = 0; //两点之间X差值 double deltaY = 0; //两点之间Y差值 if ((pPointPt != null) && (pNewLineFeedback != null)) { deltaX = pMovePt.X - pPointPt.X; deltaY = pMovePt.Y - pPointPt.Y; dSegmentLength = Math.Round(Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)), 3); dToltalLength = dToltalLength + dSegmentLength; if (frmMeasureResult != null) { frmMeasureResult.lblMeasureResult.Text = String.Format( "当前线段长度:{0:.###}{1};\r\n总长度为: {2:.###}{1}", dSegmentLength, sMapUnits, dToltalLength); dToltalLength = dToltalLength - dSegmentLength; //鼠标移动到新点重新开始计算 } frmMeasureResult.frmClosed += new FormMeasureResult.FormClosedEventHandler(frmMeasureResult_frmColsed); } break; case "MeasureArea": if (pNewPolygonFeedback != null) { pNewPolygonFeedback.MoveTo(pMovePt); } IPointCollection pPointCol = new Polygon(); IPolygon pPolygon = new PolygonClass(); IGeometry pGeo = null; ITopologicalOperator pTopo = null; for (int i = 0; i <= pAreaPointCol.PointCount - 1; i++) { pPointCol.AddPoint(pAreaPointCol.get_Point(i), ref missing, ref missing); } pPointCol.AddPoint(pMovePt, ref missing, ref missing); if (pPointCol.PointCount < 3) { return; } pPolygon = pPointCol as IPolygon; if ((pPolygon != null)) { pPolygon.Close(); pGeo = pPolygon as IGeometry; pTopo = pGeo as ITopologicalOperator; //使几何图形的拓扑正确 pTopo.Simplify(); pGeo.Project(MainMapControl.Map.SpatialReference); IArea pArea = pGeo as IArea; frmMeasureResult.lblMeasureResult.Text = String.Format( "总面积为:{0:.####}平方{1};\r\n总长度为:{2:.####}{1}", pArea.Area, sMapUnits, pPolygon.Length); pPolygon = null; } break; default: break; } }
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)//左下角鼠标坐标显示 { sMapUnit = GetMapUnit(axMapControl1.Map.MapUnits); barCoorTxt.Text = string.Format("当前坐标:X{0:#.###} Y={1:#.###}{2}", e.mapX, e.mapY, sMapUnit); pMovePt = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); //获取移动点 switch (mousedownname) { case "MeasureLength": //距离量测 if (pNewLineFeedback != null) { pNewLineFeedback.MoveTo(pMovePt); //移动至当前 } if (pPointPt != null && pNewLineFeedback != null) { double deltaX = pMovePt.X - pPointPt.X; //两点间X差 double deltaY = pMovePt.Y - pPointPt.Y; //两点间Y 差 dSegmentLength = Math.Round(Math.Sqrt(deltaX * deltaX + deltaY * deltaY), 3); dToltaLength = dToltaLength + dSegmentLength; if (frmMeasureresult != null) { frmMeasureresult.label2.Text = String.Format("当前长度线段为:{0:.###}{1};\r\n总长度为:{2:.###}{1}", dSegmentLength, sMapUnit, dToltaLength); dToltaLength = dToltaLength - dSegmentLength; //鼠标移动到新点重新开始计算 } } break; case "MeasureArea": //面积量测 if (pNewPolygonFeedback != null) { pNewPolygonFeedback.MoveTo(pMovePt); } IPointCollection pPointCol = new Polygon(); //实例化一个新的点集对象 IPolygon pPolygon = new PolygonClass(); //实例化一个面几何对象 for (int i = 0; i <= pAreaPointCollection.PointCount - 1; i++) { pPointCol.AddPoint(pAreaPointCollection.get_Point(i), ref missing, ref missing); //将全局变量中已经确定的点集赋给pPointCol这个点集对象 } pPointCol.AddPoint(pMovePt, ref missing, ref missing); //将当前的移动点赋给pPointCol这个点集对象 if (pPointCol.PointCount < 3) { return; //小于三个点无法形成面,不执行以下语句 } pPolygon = pPointCol as IPolygon; //将点集合形成一个面对象 if ((pPolygon != null)) { pPolygon.Close(); IGeometry pGeo = pPolygon; ITopologicalOperator pTopo = pGeo as ITopologicalOperator; pTopo.Simplify(); pGeo.Project(axMapControl1.Map.SpatialReference); IArea pArea = pGeo as IArea; frmMeasureresult.label2.Text = String.Format("总面积为:{0:.####}平方{1};\r\n总长度为:{2:.#####}{1}", pArea.Area, sMapUnit, pPolygon.Length); } break; } }
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) //地图移动 { if (axMapControl1.LayerCount == 0) { return; } sMapUnits = "千米";//GetMapUnit(axMapControl1.Map.MapUnits); //求量测所需的单位 #region 状态栏 //就绪 //比例尺 labelItem2.Text = " 比例尺 1:" + ((long)this.axMapControl1.MapScale).ToString(); //坐标 lbl_Coordinate.Text = "当前坐标:X:" + e.mapX.ToString() + " Y: " + e.mapY.ToString(); #endregion pMovePt = (axMapControl1.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); #region 长度量算 if (pMouseOperate == "MeasureLength") { if (pNewLineFeedback != null) { pNewLineFeedback.MoveTo(pMovePt); } double deltaX = 0; //两点之间X差值 double deltaY = 0; //两点之间Y差值 if ((pPointPt != null) && (pNewLineFeedback != null)) { deltaX = pMovePt.X - pPointPt.X; deltaY = pMovePt.Y - pPointPt.Y; dSegmentLength = Math.Round(111.199 * (Math.Sqrt((deltaY * deltaY) + (deltaX * deltaX) * (Math.Cos((pPointPt.Y + pMovePt.Y) / 2) * Math.Cos((pPointPt.Y + pMovePt.Y) / 2)))), 3); dToltalLength = dToltalLength + dSegmentLength; if (frmMeasureResult != null) { frmMeasureResult.lblMeasureResult.Text = String.Format( "当前量测的距离为:{0:.###}{1};\r\n总长度为: {2:.###}{1}", dSegmentLength, sMapUnits, dToltalLength); dToltalLength = dToltalLength - dSegmentLength; //鼠标移动到新点重新开始计算 } frmMeasureResult.frmClosed += new FrmMeasureResult.FrmClosedEventHandler(frmMeasureResult_frmColsed); } } #endregion #region 面积量算 if (pMouseOperate == "MeasureArea") { if (pNewPolygonFeedback != null) { pNewPolygonFeedback.MoveTo(pMovePt); } IPointCollection pPointCol = new Polygon(); IPolygon pPolygon = new PolygonClass(); IGeometry pGeo = null; ITopologicalOperator pTopo = null; for (int i = 0; i <= pAreaPointCol.PointCount - 1; i++) { pPointCol.AddPoint(pAreaPointCol.get_Point(i), ref missing, ref missing); } pPointCol.AddPoint(pMovePt, ref missing, ref missing); if (pPointCol.PointCount < 3) { return; } pPolygon = pPointCol as IPolygon; if ((pPolygon != null)) { pPolygon.Close(); pGeo = pPolygon as IGeometry; pTopo = pGeo as ITopologicalOperator; //使几何图形的拓扑正确 pTopo.Simplify(); pGeo.Project(axMapControl1.Map.SpatialReference); IArea pArea = pGeo as IArea; frmMeasureResult.lblMeasureResult.Text = String.Format( "总面积为:{0:.####}平方{1};\r\n总长度为:{2:.####}{1}", pArea.Area, sMapUnits, pPolygon.Length); pPolygon = null; } } #endregion #region 移动显示名称 IFeatureLayer pFeatureLayer8 = axMapControl1.Map.get_Layer(0) as IFeatureLayer; //定位的图层包括了很多要素 pFeatureLayer8.DisplayField = "name"; pFeatureLayer8.ShowTips = true; string pTip8; pTip8 = pFeatureLayer8.get_TipText(e.mapX, e.mapY, axMapControl1.ActiveView.FullExtent.Width / 1000); if (pTip8 != null && pTip8 != " ") { toolTip1.SetToolTip(axMapControl1, "这里是:" + pTip8); } else { toolTip1.SetToolTip(axMapControl1, ""); } #endregion }