/// <summary> /// 完成新建对象,取得绘制的对象,并添加到图层中 /// 建议在Map.DblClick或Map.MouseDown(Button = 2)事件中调用本方法 /// </summary> public void NewFeatureEnd() { IGeometry pGeom = null; IPointCollection pPointCollection; try { if (m_pFeedback is INewMultiPointFeedback) { INewMultiPointFeedback pMPFeed = (INewMultiPointFeedback)m_pFeedback; pMPFeed.Stop(); pGeom = (IGeometry)m_pPointCollection; } else if (m_pFeedback is INewLineFeedback) { INewLineFeedback pLineFeed = (INewLineFeedback)m_pFeedback; pLineFeed.AddPoint(m_pPoint); IPolyline pPolyLine = pLineFeed.Stop(); pPointCollection = (IPointCollection)pPolyLine; if (pPointCollection.PointCount < 2) { MessageBox.Show("至少输入两个节点"); } else { pGeom = (IGeometry)pPointCollection; } } else if (m_pFeedback is INewPolygonFeedback) { INewPolygonFeedback pPolyFeed = (INewPolygonFeedback)m_pFeedback; pPolyFeed.AddPoint(m_pPoint); IPolygon pPolygon; pPolygon = pPolyFeed.Stop(); if (pPolygon != null) { pPointCollection = (IPointCollection)pPolygon; if (pPointCollection.PointCount < 3) { MessageBox.Show("至少输入三个节点"); } else { pGeom = (IGeometry)pPointCollection; } } } CreateFeature(pGeom); m_pFeedback = null; m_bInUse = false; } catch (Exception e) { Console.WriteLine(e.Message.ToString()); } }
public void OnDblClick() { IGeometry pResultGeometry = null; 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.esriGeometryPoint: m_newMultPtFeedBack.Stop(); pResultGeometry = m_pointCollection as IGeometry; m_newMultPtFeedBack = null; break; case esriGeometryType.esriGeometryPolyline: IPolyline pPolyline = null; pPolyline = m_newLineFeedBack.Stop(); pResultGeometry = pPolyline as IGeometry; m_newLineFeedBack = null; break; case esriGeometryType.esriGeometryPolygon: IPolygon pPolygon = null; pPolygon = m_newPolyFeedBack.Stop(); pResultGeometry = pPolygon as IGeometry; m_newPolyFeedBack = null; break; } IZAware pZAware = pResultGeometry as IZAware; if (pZAware == null) { return; } pZAware.ZAware = true; //创建新要素 CreateFeature(pResultGeometry); }
public void OnDblClick() { IGeometry resultGeometry = null; 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.esriGeometryMultipoint: newMultiPointFeedback.Stop(); resultGeometry = pointCollection as IGeometry; newMultiPointFeedback = null; break; case esriGeometryType.esriGeometryPolyline: IPolyline polyline = null; polyline = newLineFeedback.Stop(); resultGeometry = polyline as IGeometry; newLineFeedback = null; break; case esriGeometryType.esriGeometryPolygon: IPolygon polygon = null; polygon = newPolygonFeedback.Stop(); resultGeometry = polygon as IGeometry; newPolygonFeedback = null; break; } IZAware zaware = resultGeometry as IZAware; zaware.ZAware = true; CreateFeature(resultGeometry);//创建新要素 }
public void EndSketch() { IGeometry resGeometry = null; IPointCollection pointColl = null; try { if ((MyfeedBack as INewMultiPointFeedback) != null) { INewMultiPointFeedback multiPointFeedback = MyfeedBack as INewMultiPointFeedback; multiPointFeedback.Stop(); } else if ((MyfeedBack as INewLineFeedback) != null) { INewLineFeedback lineFeedback = MyfeedBack as INewLineFeedback; lineFeedback.AddPoint(MycurrentMousePosition); IPolyline polyline = lineFeedback.Stop(); pointColl = polyline as IPointCollection; if (pointColl.PointCount > 1) { resGeometry = pointColl as IGeometry; } } else if ((MyfeedBack as INewPolygonFeedback) != null) { INewPolygonFeedback polygonFeedback = MyfeedBack as INewPolygonFeedback; polygonFeedback.AddPoint(MycurrentMousePosition); IPolygon polygon = polygonFeedback.Stop(); if (polygon != null) { pointColl = polygon as IPointCollection; if (pointColl.PointCount > 2) { resGeometry = pointColl as IGeometry; ITopologicalOperator pTopo = resGeometry as ITopologicalOperator; if (!pTopo.IsKnownSimple) { pTopo.Simplify(); } } } } MyfeedBack = null; If_isInUse = false; } catch { return; } }
public void SketchMouseDown(int x, int y) { if (MyselectedLayer == null) { return; } if ((MyselectedLayer as IGeoFeatureLayer) == null) { return; } IFeatureLayer featureLayer = MyselectedLayer as IFeatureLayer; IFeatureClass featureClass = featureLayer.FeatureClass; if (featureClass == null) { return; } IPoint point = MyMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); INewLineFeedback lineFeedback = null; INewPolygonFeedback polygonFeedback = null; try { if (!If_isInUse) { switch (featureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: break; case esriGeometryType.esriGeometryMultipoint: If_isInUse = true; MyfeedBack = new NewMultiPointFeedbackClass(); INewMultiPointFeedback multiPointFeedback = MyfeedBack as INewMultiPointFeedback; MypointCollection = new MultipointClass(); multiPointFeedback.Start(MypointCollection, point); break; case esriGeometryType.esriGeometryPolyline: If_isInUse = true; MyfeedBack = new NewLineFeedbackClass(); lineFeedback = MyfeedBack as INewLineFeedback; lineFeedback.Start(point); break; case esriGeometryType.esriGeometryPolygon: If_isInUse = true; MyfeedBack = new NewPolygonFeedbackClass(); polygonFeedback = MyfeedBack as INewPolygonFeedback; polygonFeedback.Start(point); break; default: break; } } else { if ((MyfeedBack as INewMultiPointFeedback) != null) { object missing = Type.Missing; MypointCollection.AddPoint(point, ref missing, ref missing); } else if ((MyfeedBack as INewLineFeedback) != null) { lineFeedback = MyfeedBack as INewLineFeedback; lineFeedback.AddPoint(point); } else if ((MyfeedBack as INewPolygonFeedback) != null) { polygonFeedback = MyfeedBack as INewPolygonFeedback; polygonFeedback.AddPoint(point); } } } catch { return; } }
public static string SketchMouseDown(IPoint ipoint_0, IActiveView iactiveView_0, IFeatureLayer ifeatureLayer_0) { INewPolylineFeedback feedback; string str; INewPolygonFeedbackEx newPolygonFeedbackEx; object value; INewPolylineFeedback newPolylineFeedback; double num; string[] strArrays; double num1; double length; if (SketchToolAssist.IsDrawTempLine == DrawTempGeometry.Line) { if (SketchToolAssist.Feedback != null) { feedback = (INewPolylineFeedback)SketchToolAssist.Feedback; feedback.AddPoint(SketchShareEx.m_pAnchorPoint); object obj = Missing.Value; object value1 = Missing.Value; SketchToolAssist.m_pPointColn.AddPoint(SketchShareEx.m_pAnchorPoint, ref obj, ref value1); } else { SketchShareEx.m_bInUse = true; SketchToolAssist.Feedback = new NewPolylineFeedback(); feedback = (INewPolylineFeedback)SketchToolAssist.Feedback; SketchToolAssist.Feedback.Display = iactiveView_0.ScreenDisplay; feedback.ChangeLineType((enumLineType)SketchToolAssist.LineType); feedback.Start(SketchShareEx.m_pAnchorPoint); SketchToolAssist.m_pPointColn = new Polyline(); object obj1 = Missing.Value; object value2 = Missing.Value; SketchToolAssist.m_pPointColn.AddPoint(SketchShareEx.m_pAnchorPoint, ref obj1, ref value2); } str = ""; } else if (SketchToolAssist.IsDrawTempLine == DrawTempGeometry.Fill) { if (SketchToolAssist.Feedback != null) { newPolygonFeedbackEx = (INewPolygonFeedbackEx)SketchToolAssist.Feedback; newPolygonFeedbackEx.AddPoint(SketchShareEx.m_pAnchorPoint); object obj2 = Missing.Value; object value3 = Missing.Value; SketchToolAssist.m_pPointColn.AddPoint(SketchShareEx.m_pAnchorPoint, ref obj2, ref value3); } else { SketchShareEx.m_bInUse = true; SketchToolAssist.Feedback = new NewPolygonFeedbackEx(); newPolygonFeedbackEx = (INewPolygonFeedbackEx)SketchToolAssist.Feedback; SketchToolAssist.Feedback.Display = iactiveView_0.ScreenDisplay; newPolygonFeedbackEx.ChangeLineType((enumLineType)SketchToolAssist.LineType); newPolygonFeedbackEx.Start(SketchShareEx.m_pAnchorPoint); SketchToolAssist.m_pPointColn = new Polygon(); object obj3 = Missing.Value; object value4 = Missing.Value; SketchToolAssist.m_pPointColn.AddPoint(SketchShareEx.m_pAnchorPoint, ref obj3, ref value4); } str = ""; } else if (SketchToolAssist.IsDrawTempLine == DrawTempGeometry.Point) { SketchToolAssist.TempLine = SketchShareEx.m_pAnchorPoint; str = ""; } else if (ifeatureLayer_0 == null) { str = ""; } else if (ifeatureLayer_0.FeatureClass != null) { string str1 = ""; string unit = ""; SketchShareEx.IsFixDirection = false; SketchShareEx.IsFixLength = false; if (SketchToolAssist.Feedback == null) { if (ifeatureLayer_0.FeatureClass.FeatureType == esriFeatureType.esriFTAnnotation) { try { Editor.EditWorkspace.StartEditOperation(); IFeature feature = ifeatureLayer_0.FeatureClass.CreateFeature(); int num2 = 0; object fieldValue = Editor.CurrentEditTemplate.GetFieldValue("SymbolID"); if (fieldValue != null) { num2 = Convert.ToInt32(fieldValue); } ITextElement textElement = CreateFeatureTool.MakeTextElement("文本", 0, ipoint_0, num2); IAnnotationFeature2 annotationFeature2 = feature as IAnnotationFeature2; annotationFeature2.LinkedFeatureID = -1; annotationFeature2.AnnotationClassID = 0; annotationFeature2.Annotation = textElement as IElement; EditorEvent.NewRow(feature); feature.Store(); Editor.EditWorkspace.StopEditOperation(); EditorEvent.AfterNewRow(feature); iactiveView_0.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); iactiveView_0.FocusMap.ClearSelection(); iactiveView_0.FocusMap.SelectFeature(ifeatureLayer_0, feature); iactiveView_0.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } catch (Exception exception) { Logger.Current.Error("", exception, ""); } } else if (ifeatureLayer_0.FeatureClass.FeatureType != esriFeatureType.esriFTDimension) { value = Missing.Value; switch (ifeatureLayer_0.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: { CreateFeatureTool.CreateFeature(ipoint_0, iactiveView_0, ifeatureLayer_0); break; } case esriGeometryType.esriGeometryMultipoint: { SketchShareEx.m_bInUse = true; SketchToolAssist.Feedback = new NewMultiPointFeedback(); INewMultiPointFeedback newMultiPointFeedback = (INewMultiPointFeedback)SketchToolAssist.Feedback; SketchToolAssist.Feedback.Display = iactiveView_0.ScreenDisplay; SketchShareEx.m_pPointCollection = new Multipoint(); newMultiPointFeedback.Start(SketchShareEx.m_pPointCollection, ipoint_0); break; } case esriGeometryType.esriGeometryPolyline: { SketchShareEx.m_bInUse = true; SketchToolAssist.Feedback = new NewPolylineFeedback(); newPolylineFeedback = (INewPolylineFeedback)SketchToolAssist.Feedback; SketchToolAssist.Feedback.Display = iactiveView_0.ScreenDisplay; newPolylineFeedback.Start(ipoint_0); SketchShareEx.PointCount = 1; SketchShareEx.StartPoint = ipoint_0; SketchToolAssist.m_pPointColn = new Polyline(); SketchToolAssist.m_pPointColn.AddPoint(ipoint_0, ref value, ref value); unit = CommonHelper.GetUnit(iactiveView_0.FocusMap.MapUnits); num = CommonHelper.measureLength(ipoint_0, 1, ref SketchShareEx.m_pLastPoint1, ref SketchShareEx.m_pEndPoint1, ref SketchShareEx.m_totalLength); strArrays = new string[] { "距离 = ", num.ToString("0.###"), unit, ", 总长度 = ", SketchShareEx.m_totalLength.ToString("0.###"), unit }; str1 = string.Concat(strArrays); break; } case esriGeometryType.esriGeometryPolygon: { SketchShareEx.m_bInUse = true; SketchToolAssist.Feedback = new NewPolygonFeedbackEx(); INewPolygonFeedbackEx feedback1 = (INewPolygonFeedbackEx)SketchToolAssist.Feedback; SketchToolAssist.Feedback.Display = iactiveView_0.ScreenDisplay; feedback1.Start(ipoint_0); SketchShareEx.PointCount = 0; SketchToolAssist.m_pPointColn = new Polygon(); SketchShareEx.StartPoint = ipoint_0; unit = CommonHelper.GetUnit(iactiveView_0.FocusMap.MapUnits); num1 = CommonHelper.measureArea(ipoint_0, 1, ref SketchToolAssist.m_pPointColn); length = (SketchToolAssist.m_pPointColn as IPolygon).Length; if (num1 <= 0) { break; } str1 = string.Format("周长 = {0:0.###} {1} ,总面积 = {2:0.###} 平方{1}", length, unit, num1); break; } } } else { SketchToolAssist.Feedback = new NewDimensionFeedback(); try { (SketchToolAssist.Feedback as INewDimensionFeedback).ReferenceScale = (iactiveView_0 as IMap).ReferenceScale; (SketchToolAssist.Feedback as INewDimensionFeedback).ReferenceScaleUnits = (iactiveView_0 as IMap).MapUnits; } catch { } SketchToolAssist.Feedback.Display = iactiveView_0.ScreenDisplay; (SketchToolAssist.Feedback as INewDimensionFeedback).Start(ipoint_0); SketchShareEx.PointCount = 1; } } else if (SketchToolAssist.Feedback is INewDimensionFeedback) { SketchShareEx.PointCount = SketchShareEx.PointCount + 1; (SketchToolAssist.Feedback as INewDimensionFeedback).AddPoint(ipoint_0); if (SketchShareEx.PointCount == 3) { IDimensionShape dimensionShape = (SketchToolAssist.Feedback as INewDimensionFeedback).Stop(); CreateFeatureTool.CreateDimensionFeature(dimensionShape, (SketchToolAssist.Feedback as INewDimensionFeedback).DimensionType, iactiveView_0, ifeatureLayer_0); } } else if (SketchToolAssist.Feedback is INewMultiPointFeedback) { value = Missing.Value; SketchShareEx.m_pPointCollection.AddPoint(ipoint_0, ref value, ref value); (SketchToolAssist.Feedback as INewMultiPointFeedback).Start(SketchShareEx.m_pPointCollection, ipoint_0); } else if (SketchToolAssist.Feedback is INewLineFeedback) { newPolylineFeedback = (INewPolylineFeedback)SketchToolAssist.Feedback; value = Missing.Value; newPolylineFeedback.AddPoint(ipoint_0); SketchToolAssist.m_pPointColn.AddPoint(ipoint_0, ref value, ref value); SketchShareEx.PointCount = SketchShareEx.PointCount + 1; unit = CommonHelper.GetUnit(iactiveView_0.FocusMap.MapUnits); num = CommonHelper.measureLength(ipoint_0, 1, ref SketchShareEx.m_pLastPoint1, ref SketchShareEx.m_pEndPoint1, ref SketchShareEx.m_totalLength); strArrays = new string[] { "距离 = ", num.ToString("0.###"), unit, ", 总长度 = ", SketchShareEx.m_totalLength.ToString("0.###"), unit }; str1 = string.Concat(strArrays); } else if (SketchToolAssist.Feedback is INewPolygonFeedback) { ((INewPolygonFeedbackEx)SketchToolAssist.Feedback).AddPoint(ipoint_0); SketchShareEx.PointCount = SketchShareEx.PointCount + 1; unit = CommonHelper.GetUnit(iactiveView_0.FocusMap.MapUnits); num1 = CommonHelper.measureArea(ipoint_0, 1, ref SketchToolAssist.m_pPointColn); length = (SketchToolAssist.m_pPointColn as IPolygon).Length; if (num1 > 0) { str1 = string.Format("周长 = {0:0.###} {1} ,总面积 = {2:0.###} 平方{1}", length, unit, num1); } } if (SketchShareEx.LastPoint == null) { SketchShareEx.LastPoint = new ESRI.ArcGIS.Geometry.Point(); } SketchShareEx.LastPoint.PutCoords(ipoint_0.X, ipoint_0.Y); str = str1; } else { str = ""; } return(str); }
public void OnMouseDown(int button, int shift, int x, int y) { try { IPoint pPt = m_activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); if (m_EngineEditor == null) { return; } if (m_EngineEditor.EditState != esriEngineEditState.esriEngineStateEditing) { return; } if (m_EngineEditLayers == null) { return; } IFeatureLayer pFeatLyr = m_EngineEditLayers.TargetLayer; if (pFeatLyr == null) { return; } IFeatureClass pFeatCls = pFeatLyr.FeatureClass; if (pFeatCls == null) { return; } //解决编辑要素的Z值问题 IZAware pZAware = pPt as IZAware; pZAware.ZAware = true; pPt.Z = 0; object missing = Type.Missing; m_Map.ClearSelection(); switch (pFeatCls.ShapeType) { case esriGeometryType.esriGeometryPoint: //当为点层时,直接创建要素 CreateFeature(pPt as IGeometry); break; case esriGeometryType.esriGeometryMultipoint: //点集的处理方式 if (m_pointCollection == null) { m_pointCollection = new MultipointClass(); } else { m_pointCollection.AddPoint(pPt, ref missing, ref missing); } if (m_newMultPtFeedBack == null) { m_newMultPtFeedBack = new NewMultiPointFeedbackClass(); m_newMultPtFeedBack.Display = m_activeView.ScreenDisplay; m_newMultPtFeedBack.Start(m_pointCollection, pPt); } break; case esriGeometryType.esriGeometryPolyline: //多义线处理方式 if (m_newLineFeedBack == null) { m_newLineFeedBack = new NewLineFeedbackClass(); m_newLineFeedBack.Display = m_activeView.ScreenDisplay; m_newLineFeedBack.Start(pPt); } else { m_newLineFeedBack.AddPoint(pPt); } break; case esriGeometryType.esriGeometryPolygon: //多边形处理方式 if (m_newPolyFeedBack == null) { m_newPolyFeedBack = new NewPolygonFeedbackClass(); m_newPolyFeedBack.Display = m_activeView.ScreenDisplay; m_newPolyFeedBack.Start(pPt); } else { m_newPolyFeedBack.AddPoint(pPt); } break; } } catch (Exception ex) { //SysLogHelper.WriteOperationLog("要素创建错误", ex.Source, "数据编辑"); } }
/// <summary> /// 完成新建对象,取得绘制的对象,并添加到图层中 /// 建议在Map.DblClick或Map.MouseDown(Button = 2)事件中调用本方法 /// </summary> public void NewFeatureEnd() { IGeometry pGeom = null; IPointCollection pPointCollection; object obj = Type.Missing; try { if (m_pFeedback is INewMultiPointFeedback) { INewMultiPointFeedback pMPFeed = (INewMultiPointFeedback)m_pFeedback; pMPFeed.Stop(); pGeom = (IGeometry)m_pPointCollection; if (m_GeometryCollection == null) { m_GeometryCollection = new PointClass() as IGeometryCollection; } m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection); } else if (m_pFeedback is INewLineFeedback) { INewLineFeedback pLineFeed = (INewLineFeedback)m_pFeedback; if (m_GeometryCollection == null) { m_GeometryCollection = new PolylineClass() as IGeometryCollection; } IPolyline pPolyLine = pLineFeed.Stop(); pPointCollection = (IPointCollection)pPolyLine; if (pPointCollection.PointCount < 2) { MessageBox.Show("至少输入两个节点"); } else { pGeom = (IGeometry)pPointCollection; } m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection); } else if (m_pFeedback is INewPolygonFeedback) { INewPolygonFeedback pPolyFeed = (INewPolygonFeedback)m_pFeedback; if (m_GeometryCollection == null) { m_GeometryCollection = new PolygonClass() as IGeometryCollection; } IPolygon pPolygon; pPolygon = pPolyFeed.Stop(); if (pPolygon != null) { pPointCollection = (IPointCollection)pPolygon; if (pPointCollection.PointCount < 3) { MessageBox.Show("至少输入三个节点"); } else { pGeom = (IGeometry)pPointCollection; } m_GeometryCollection.AddGeometryCollection(pGeom as IGeometryCollection); } } if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { IPolyline pline = MyMapHelp.PolygonToPolyline(m_GeometryCollection as IPolygon); CreateFeature(pline as IGeometry); } else { CreateFeature(m_GeometryCollection as IGeometry); } m_pFeedback = null; m_bInUse = false; m_GeometryCollection = null; } catch (Exception e) { m_pFeedback = null; m_bInUse = false; m_GeometryCollection = null; Console.WriteLine(e.Message.ToString()); } }
public void OnMouseDown(int button, int shift, int x, int y) { try { IPoint point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); if (engineEditor == null) { return; } if (engineEditor.EditState != esriEngineEditState.esriEngineStateEditing) { return; } if (engineEditLayers == null) { return; } IFeatureLayer featureLayer = engineEditLayers.TargetLayer; if (featureLayer == null) { return; } IFeatureClass featureClass = featureLayer.FeatureClass; if (featureClass == null) { return; } //解决编辑要素的Z值问题 IZAware zaware = point as IZAware; zaware.ZAware = true; point.Z = 0; object missing = Type.Missing; map.ClearSelection(); switch (featureClass.ShapeType) { //当为点层时,直接创建要素 case esriGeometryType.esriGeometryPoint: CreateFeature(point as IGeometry); break; //点集的处理方式 case esriGeometryType.esriGeometryMultipoint: if (pointCollection == null) { pointCollection = new MultipointClass(); } else { pointCollection.AddPoint(point, ref missing, ref missing); } if (newMultiPointFeedback == null) { newMultiPointFeedback = new NewMultiPointFeedbackClass(); newMultiPointFeedback.Display = activeView.ScreenDisplay; newMultiPointFeedback.Start(pointCollection, point); } break; //多段线处理方式 case esriGeometryType.esriGeometryPolyline: if (newLineFeedback == null) { newLineFeedback = new NewLineFeedbackClass(); newLineFeedback.Display = activeView.ScreenDisplay; newLineFeedback.Start(point); } else { newLineFeedback.AddPoint(point); } break; //多边形处理方式 case esriGeometryType.esriGeometryPolygon: if (newPolygonFeedback == null) { newPolygonFeedback = new NewPolygonFeedbackClass(); newPolygonFeedback.Display = activeView.ScreenDisplay; newPolygonFeedback.Start(point); } else { newPolygonFeedback.AddPoint(point); } break; } } catch (Exception exception) {} }
/// <summary> /// 新建对象方法 /// 当前图层为点图层时,每调用一次就新点一个点对象 /// 当前图层为线图层或面图层时,第一次调用开始新建对象,并添加当前点, /// 以后每调用一次,即向新对象中添加一个点,调用NewFeatureEnd方法完成对象创建 /// 在Map.MouseDown事件中调用本方法 /// </summary> /// <param name="x">鼠标X坐标,屏幕坐标</param> /// <param name="y">鼠标Y坐标,屏幕坐标</param> public void NewFeatureMouseDown(int x, int y) { INewPolygonFeedback pPolyFeed; INewLineFeedback pLineFeed; try { if (m_pCurrentLayer == null) { return; } if (!(m_pCurrentLayer is IGeoFeatureLayer)) { return; } IFeatureLayer pFeatureLayer = (IFeatureLayer)m_pCurrentLayer; if (pFeatureLayer.FeatureClass == null) { return; } IActiveView pActiveView = (IActiveView)m_pMap; IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); // 如果是新开始创建的对象,则相应的创建一个新的Feedback对象; // 否则,向已存在的Feedback对象中加点 if (!m_bInUse) { m_pMap.ClearSelection(); //清除地图选中对象 switch (pFeatureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: CreateFeature(pPoint); break; case esriGeometryType.esriGeometryMultipoint: m_bInUse = true; m_pFeedback = new NewMultiPointFeedbackClass(); INewMultiPointFeedback pMPFeed = (INewMultiPointFeedback)m_pFeedback; m_pPointCollection = new MultipointClass(); pMPFeed.Start(m_pPointCollection, pPoint); break; case esriGeometryType.esriGeometryPolyline: m_bInUse = true; m_pFeedback = new NewLineFeedbackClass(); pLineFeed = (INewLineFeedback)m_pFeedback; pLineFeed.Start(pPoint); break; case esriGeometryType.esriGeometryPolygon: m_bInUse = true; m_pFeedback = new NewPolygonFeedbackClass(); pPolyFeed = (INewPolygonFeedback)m_pFeedback; pPolyFeed.Start(pPoint); break; } if (m_pFeedback != null) { m_pFeedback.Display = pActiveView.ScreenDisplay; } } else { if (m_pFeedback is INewMultiPointFeedback) { object obj = Missing.Value; m_pPointCollection.AddPoint(pPoint, ref obj, ref obj); } else if (m_pFeedback is INewLineFeedback) { pLineFeed = (INewLineFeedback)m_pFeedback; pLineFeed.AddPoint(pPoint); } else if (m_pFeedback is INewPolygonFeedback) { pPolyFeed = (INewPolygonFeedback)m_pFeedback; pPolyFeed.AddPoint(pPoint); } } } catch (Exception e) { Console.WriteLine(e.Message.ToString()); } }
public static string SketchMouseDown(IActiveView pActiveView, IFeatureLayer pFeatureLayer) { INewPolylineFeedback feedback; string str; INewPolygonFeedbackEx newPolygonFeedbackEx; object value; INewPolylineFeedback newPolylineFeedback; INewPolygonFeedbackEx feedback1; double num; double length; if (SketchToolAssist.IsDrawTempLine == DrawTempGeometry.Line) { if (SketchToolAssist.Feedback != null) { feedback = (INewPolylineFeedback)SketchToolAssist.Feedback; feedback.AddPoint(SketchToolAssist.m_pAnchorPoint); object obj = Missing.Value; object value1 = Missing.Value; SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref obj, ref value1); } else { SketchToolAssist.m_bInUse = true; SketchToolAssist.Feedback = new NewPolylineFeedback() as IDisplayFeedback2; feedback = (INewPolylineFeedback)SketchToolAssist.Feedback; SketchToolAssist.Feedback.Display = pActiveView.ScreenDisplay; feedback.ChangeLineType(SketchToolAssist.LineType); feedback.Start(SketchToolAssist.m_pAnchorPoint); SketchToolAssist.m_pPointColn = new Polyline(); object obj1 = Missing.Value; object value2 = Missing.Value; SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref obj1, ref value2); } str = ""; } else if (SketchToolAssist.IsDrawTempLine == DrawTempGeometry.Fill) { if (SketchToolAssist.Feedback != null) { newPolygonFeedbackEx = (INewPolygonFeedbackEx)SketchToolAssist.Feedback; newPolygonFeedbackEx.AddPoint(SketchToolAssist.m_pAnchorPoint); object obj2 = Missing.Value; object value3 = Missing.Value; SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref obj2, ref value3); } else { SketchToolAssist.m_bInUse = true; SketchToolAssist.Feedback = new NewPolygonFeedbackEx(); newPolygonFeedbackEx = (INewPolygonFeedbackEx)SketchToolAssist.Feedback; SketchToolAssist.Feedback.Display = pActiveView.ScreenDisplay; newPolygonFeedbackEx.ChangeLineType(SketchToolAssist.LineType); newPolygonFeedbackEx.Start(SketchToolAssist.m_pAnchorPoint); SketchToolAssist.m_pPointColn = new Polygon(); object obj3 = Missing.Value; object value4 = Missing.Value; SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref obj3, ref value4); } str = ""; } else if (SketchToolAssist.IsDrawTempLine == DrawTempGeometry.Point) { SketchToolAssist.TempLine = SketchToolAssist.m_pAnchorPoint; str = ""; } else if (pFeatureLayer == null) { str = ""; } else if (pFeatureLayer.FeatureClass != null) { string str1 = ""; string unit = ""; SketchToolAssist.IsFixDirection = false; SketchToolAssist.IsFixLength = false; if (SketchToolAssist.Feedback == null) { if (pFeatureLayer.FeatureClass.FeatureType == esriFeatureType.esriFTAnnotation) { try { Editor.EditWorkspace.StartEditOperation(); IFeature feature = pFeatureLayer.FeatureClass.CreateFeature(); ITextElement textElement = CreateFeatureTool.MakeTextElement("文本", 0, SketchToolAssist.m_pAnchorPoint); IAnnotationFeature2 annotationFeature2 = feature as IAnnotationFeature2; annotationFeature2.LinkedFeatureID = -1; annotationFeature2.AnnotationClassID = 0; annotationFeature2.Annotation = textElement as IElement; EditorEvent.NewRow(feature); feature.Store(); Editor.EditWorkspace.StopEditOperation(); EditorEvent.AfterNewRow(feature); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); pActiveView.FocusMap.ClearSelection(); pActiveView.FocusMap.SelectFeature(pFeatureLayer, feature); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } catch (Exception exception) { Logger.Current.Error("", exception, ""); } } else if (pFeatureLayer.FeatureClass.FeatureType != esriFeatureType.esriFTDimension) { value = Missing.Value; switch (pFeatureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: { CreateFeatureTool.CreateFeature(SketchToolAssist.m_pAnchorPoint, pActiveView, pFeatureLayer); break; } case esriGeometryType.esriGeometryMultipoint: { SketchToolAssist.m_bInUse = true; SketchToolAssist.Feedback = new NewMultiPointFeedback(); INewMultiPointFeedback newMultiPointFeedback = (INewMultiPointFeedback)SketchToolAssist.Feedback; SketchToolAssist.Feedback.Display = pActiveView.ScreenDisplay; SketchToolAssist.m_pPointCollection = new Multipoint(); newMultiPointFeedback.Start(SketchToolAssist.m_pPointCollection, SketchToolAssist.m_pAnchorPoint); break; } case esriGeometryType.esriGeometryPolyline: { SketchToolAssist.m_bInUse = true; SketchToolAssist.Feedback = new NewPolylineFeedback(); newPolylineFeedback = (INewPolylineFeedback)SketchToolAssist.Feedback; newPolylineFeedback.ChangeLineType(SketchToolAssist.LineType); SketchToolAssist.Feedback.Display = pActiveView.ScreenDisplay; newPolylineFeedback.Start(SketchToolAssist.m_pAnchorPoint); SketchToolAssist.m_PointCount = 1; SketchToolAssist.StartPoint = SketchToolAssist.m_pAnchorPoint; SketchToolAssist.m_pPointColn = new Polyline(); SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref value, ref value); unit = CommonHelper.GetUnit(pActiveView.FocusMap.MapUnits); break; } case esriGeometryType.esriGeometryPolygon: { SketchToolAssist.m_bInUse = true; SketchToolAssist.Feedback = new NewPolygonFeedbackEx(); feedback1 = (INewPolygonFeedbackEx)SketchToolAssist.Feedback; feedback1.ChangeLineType(SketchToolAssist.LineType); SketchToolAssist.Feedback.Display = pActiveView.ScreenDisplay; feedback1.Start(SketchToolAssist.m_pAnchorPoint); SketchToolAssist.m_PointCount = 0; SketchToolAssist.m_pPointColn = new Polygon(); SketchToolAssist.StartPoint = SketchToolAssist.m_pAnchorPoint; unit = CommonHelper.GetUnit(pActiveView.FocusMap.MapUnits); num = CommonHelper.measureArea(SketchToolAssist.m_pAnchorPoint, 1, ref SketchToolAssist.m_pPointColn); length = (SketchToolAssist.m_pPointColn as IPolygon).Length; if (num <= 0) { break; } str1 = string.Format("周长 = {0:0.###} {1} ,总面积 = {2:0.###} 平方{1}", length, unit, num); break; } } } else { SketchToolAssist.Feedback = new NewDimensionFeedback(); try { (SketchToolAssist.Feedback as INewDimensionFeedback).ReferenceScale = (pActiveView as IMap).ReferenceScale; (SketchToolAssist.Feedback as INewDimensionFeedback).ReferenceScaleUnits = (pActiveView as IMap).MapUnits; } catch { } SketchToolAssist.Feedback.Display = pActiveView.ScreenDisplay; (SketchToolAssist.Feedback as INewDimensionFeedback).Start(SketchToolAssist.m_pAnchorPoint); SketchToolAssist.m_PointCount = 1; } } else if (SketchToolAssist.Feedback is INewDimensionFeedback) { SketchToolAssist.m_PointCount = SketchToolAssist.m_PointCount + 1; (SketchToolAssist.Feedback as INewDimensionFeedback).AddPoint(SketchToolAssist.m_pAnchorPoint); if (SketchToolAssist.m_PointCount == 3) { IDimensionShape dimensionShape = (SketchToolAssist.Feedback as INewDimensionFeedback).Stop(); CreateFeatureTool.CreateDimensionFeature(dimensionShape, (SketchToolAssist.Feedback as INewDimensionFeedback).DimensionType, pActiveView, pFeatureLayer); } } else if (SketchToolAssist.Feedback is INewMultiPointFeedback) { value = Missing.Value; SketchToolAssist.m_pPointCollection.AddPoint(SketchToolAssist.m_pAnchorPoint, ref value, ref value); (SketchToolAssist.Feedback as INewMultiPointFeedback).Start(SketchToolAssist.m_pPointCollection, SketchToolAssist.m_pAnchorPoint); } else if (SketchToolAssist.Feedback is INewLineFeedback) { newPolylineFeedback = (INewPolylineFeedback)SketchToolAssist.Feedback; value = Missing.Value; newPolylineFeedback.AddPoint(SketchToolAssist.m_pAnchorPoint); SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref value, ref value); SketchToolAssist.m_PointCount = SketchToolAssist.m_PointCount + 1; unit = CommonHelper.GetUnit(pActiveView.FocusMap.MapUnits); } else if (SketchToolAssist.Feedback is INewPolygonFeedback) { feedback1 = (INewPolygonFeedbackEx)SketchToolAssist.Feedback; feedback1.AddPoint(SketchToolAssist.m_pAnchorPoint); SketchToolAssist.m_PointCount = SketchToolAssist.m_PointCount + 1; unit = CommonHelper.GetUnit(pActiveView.FocusMap.MapUnits); num = CommonHelper.measureArea(SketchToolAssist.m_pAnchorPoint, 1, ref SketchToolAssist.m_pPointColn); length = (SketchToolAssist.m_pPointColn as IPolygon).Length; if (num > 0) { str1 = string.Format("周长 = {0:0.###} {1} ,总面积 = {2:0.###} 平方{1}", length, unit, num); } object value5 = Missing.Value; object obj5 = Missing.Value; SketchToolAssist.m_pPointColn.AddPoint(SketchToolAssist.m_pAnchorPoint, ref value5, ref obj5); } if (SketchToolAssist.LastPoint == null) { SketchToolAssist.LastPoint = new ESRI.ArcGIS.Geometry.Point(); } SketchToolAssist.LastPoint.PutCoords(SketchToolAssist.m_pAnchorPoint.X, SketchToolAssist.m_pAnchorPoint.Y); str = str1; } else { str = ""; } return(str); }
private void method_2(IPoint ipoX) { string unit; double num; string[] str; string str1; double num1; string str2; SketchShareEx.IsFixDirection = false; SketchShareEx.IsFixLength = false; IActiveView focusMap = (IActiveView)_context.FocusMap; if (!SketchShareEx.m_bInUse) { if (Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer != null) { IFeatureLayer featureLayer = Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer; if (featureLayer.FeatureClass == null) { return; } if (featureLayer.FeatureClass.FeatureType != esriFeatureType.esriFTAnnotation) { switch (featureLayer.FeatureClass.ShapeType) { case esriGeometryType.esriGeometryPoint: { CreateFeatureTool.CreateFeature(ipoX, _context.FocusMap as IActiveView, Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer); break; } case esriGeometryType.esriGeometryMultipoint: { SketchShareEx.m_bInUse = true; SketchToolAssist.Feedback = new NewMultiPointFeedback(); INewMultiPointFeedback feedback = (INewMultiPointFeedback)SketchToolAssist.Feedback; SketchShareEx.m_pPointCollection = new Multipoint(); feedback.Start(SketchShareEx.m_pPointCollection, ipoX); break; } case esriGeometryType.esriGeometryPolyline: { SketchShareEx.m_bInUse = true; SketchToolAssist.Feedback = new NewLineFeedback(); ((INewLineFeedback)SketchToolAssist.Feedback).Start(ipoX); SketchShareEx.PointCount = SketchShareEx.PointCount + 1; if (!this.bool_0) { break; } unit = Common.GetUnit(_context.FocusMap.MapUnits); num = Common.measureLength(ipoX, 1, ref SketchShareEx.m_pLastPoint1, ref SketchShareEx.m_pEndPoint1, ref SketchShareEx.m_totalLength); str = new string[] { "距离 = ", num.ToString("0.###"), unit, ", 总长度 = ", SketchShareEx.m_totalLength.ToString("0.###"), unit }; str1 = string.Concat(str); _context.SetStatus(str1); break; } case esriGeometryType.esriGeometryPolygon: { SketchShareEx.m_bInUse = true; SketchToolAssist.Feedback = new NewPolygonFeedback(); ((INewPolygonFeedback)SketchToolAssist.Feedback).Start(ipoX); SketchShareEx.PointCount = SketchShareEx.PointCount + 1; if (!this.bool_0) { break; } unit = string.Concat(" 平方", Common.GetUnit(_context.FocusMap.MapUnits)); num1 = Common.measureArea(ipoX, 1, ref SketchToolAssist.m_pPointColn); if (num1 <= 0) { break; } str2 = string.Concat("总面积 = ", num1.ToString("0.###"), unit); _context.SetStatus(str2); break; } } } else { try { Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StartEditOperation(); IFeature feature = featureLayer.FeatureClass.CreateFeature(); ITextElement textElement = CreateFeatureTool.MakeTextElement("文本", 0, ipoX); IAnnotationFeature2 annotationFeature2 = feature as IAnnotationFeature2; annotationFeature2.LinkedFeatureID = -1; annotationFeature2.AnnotationClassID = 0; annotationFeature2.Annotation = textElement as IElement; EditorEvent.NewRow(feature); feature.Store(); Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace.StopEditOperation(); EditorEvent.AfterNewRow(feature); focusMap.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); _context.FocusMap.ClearSelection(); _context.FocusMap.SelectFeature(featureLayer, feature); focusMap.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } catch (Exception exception) { CErrorLog.writeErrorLog(this, exception, ""); } } if (SketchToolAssist.Feedback != null) { SketchToolAssist.Feedback.Display = focusMap.ScreenDisplay; } } else { return; } } else if (SketchToolAssist.Feedback is INewMultiPointFeedback) { object value = Missing.Value; SketchShareEx.m_pPointCollection.AddPoint(ipoX, ref value, ref value); } else if (SketchToolAssist.Feedback is INewLineFeedback) { ((INewLineFeedback)SketchToolAssist.Feedback).AddPoint(ipoX); SketchShareEx.PointCount = SketchShareEx.PointCount + 1; if (this.bool_0) { unit = Common.GetUnit(_context.FocusMap.MapUnits); num = Common.measureLength(ipoX, 1, ref SketchShareEx.m_pLastPoint1, ref SketchShareEx.m_pEndPoint1, ref SketchShareEx.m_totalLength); str = new string[] { "距离 = ", num.ToString("0.###"), unit, ", 总长度 = ", SketchShareEx.m_totalLength.ToString("0.###"), unit }; str1 = string.Concat(str); _context.SetStatus(str1); } } else if (SketchToolAssist.Feedback is INewPolygonFeedback) { ((INewPolygonFeedback)SketchToolAssist.Feedback).AddPoint(ipoX); SketchShareEx.PointCount = SketchShareEx.PointCount + 1; if (this.bool_0) { unit = string.Concat(" 平方", Common.GetUnit(_context.FocusMap.MapUnits)); num1 = Common.measureArea(ipoX, 1, ref SketchToolAssist.m_pPointColn); if (num1 > 0) { str2 = string.Concat("总面积 = ", num1.ToString("0.###"), unit); _context.SetStatus(str2); } } } SketchShareEx.LastPoint = new ESRI.ArcGIS.Geometry.Point(); SketchShareEx.LastPoint.PutCoords(ipoX.X, ipoX.Y); }