public override void OnClick() { _context.SetCurrentTool(this); activeView = _context.FocusMap as IActiveView; _order = 0; rectangleFeedback = null; }
private void buttonItem19_Click(object sender, EventArgs e) { m_sketchshape = "rectangle"; m_NewPolygonFeedback = null; m_RecFeedback = null; m_MapCtrls.CurrentTool = null; m_MapCtrls.ActiveView.Refresh(); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button == 1) { IPoint point = this.m_mapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); switch (this.DrawType) { case EnumDrawType.circle: if (this.m_circleFeedback == null) { this.m_circleFeedback = new NewCircleFeedbackClass(); this.m_circleFeedback.Display = this.m_mapControl.ActiveView.ScreenDisplay; this.m_circleFeedback.Start(point); } break; case EnumDrawType.ellipse: this.DrawEllipse(); break; case EnumDrawType.square: if (this.m_rectangleFeedback == null) { this.m_rectangleFeedback = new NewRectangleFeedbackClass(); this.m_rectangleFeedback.Display = this.m_mapControl.ActiveView.ScreenDisplay; this.m_rectangleFeedback.Start(point); } break; case EnumDrawType.rectangle: this.DrawRectangle(); break; case EnumDrawType.polygon: if (this.m_polygonFeedback == null) { this.m_polygonFeedback = new NewPolygonFeedbackClass(); this.m_polygonFeedback.Display = this.m_mapControl.ActiveView.ScreenDisplay; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); this.m_polygonFeedback.Start(point); } else { this.m_polygonFeedback.AddPoint(point); } break; } } }
public override void OnMouseUp(int Button, int Shift, int X, int Y) { IPoint point = this.m_mapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IGeometry geometry = null; IElement element = null; switch (this.DrawType) { case EnumDrawType.circle: if (this.m_circleFeedback != null) { ICircularArc circularArc = this.m_circleFeedback.Stop(); this.m_circleFeedback = null; if (circularArc == null || circularArc.IsPoint) { return; } geometry = MapAPI.ConvertCircularArcToPolygon(circularArc); element = new CircleElementClass(); } break; case EnumDrawType.square: if (this.m_rectangleFeedback != null) { geometry = this.m_rectangleFeedback.Stop(point); if ((geometry as IPointCollection).PointCount == 2) { this.m_rectangleFeedback = null; return; } this.m_rectangleFeedback = null; element = new PolygonElementClass(); } break; } if (geometry != null) { element.Geometry = geometry; this.AppendNodeToTreeList(element); } }
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { #region 处理各种交互情况 switch (m_sketchshape) { case "polygon": { IScreenDisplay iSDisplay = m_MapCtrls.ActiveView.ScreenDisplay; IPoint newPoint = new PointClass(); newPoint = iSDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); if (e.button == 1) { //左单击画多边形添加点: if (m_NewPolygonFeedback == null) { m_NewPolygonFeedback = new NewPolygonFeedbackClass(); m_NewPolygonFeedback.Display = iSDisplay; m_NewPolygonFeedback.Start(newPoint); } else { m_NewPolygonFeedback.AddPoint(newPoint); } } if (e.button == 2) { if (m_NewPolygonFeedback == null) { return; } //右键结束绘制: m_NewPolygonFeedback.AddPoint(newPoint); m_NewPolygon = m_NewPolygonFeedback.Stop(); //若是逆时针创建,反转一下,变为顺时针: IArea feedBackArea = m_NewPolygon as IArea; if (feedBackArea.Area < 0) { m_NewPolygon.ReverseOrientation(); } IGeometry newGeometry = m_NewPolygon as IGeometry; IFeatureWorkspace checkWorkspace = m_GlobalWorkspace as IFeatureWorkspace; IFeatureClass checkFeatureClass = checkWorkspace.OpenFeatureClass("CheckArea"); if (!(m_EditWorkspace.IsBeingEdited())) { m_EditWorkspace.StartEditing(false); } m_EditWorkspace.StartEditOperation(); int OID = CheckFeatueEditor.InsertNewFeature(newGeometry, checkFeatureClass, AppManager.GetInstance().TaskName); m_EditWorkspace.StopEditOperation(); //ISelectionEnvironment selectionEnv = new SelectionEnvironmentClass(); //selectionEnv.AreaSelectionMethod = esriSpatialRelEnum.esriSpatialRelOverlaps; //selectionEnv.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew; //this.m_MapCtrls.ActiveView.FocusMap.SelectByShape(feature.Shape, null, true); //this.m_MapCtrls.ActiveView.FocusMap.SelectByShape(feature.Shape, selectionEnv, true); //m_MapCtrls.Map.SelectByShape(m_NewPolygon, null, true); ILayer iLayer = m_MapCtrls.Layer[0]; IFeature iFeature = checkFeatureClass.GetFeature(OID); clearFeatureSelection(); m_MapCtrls.Map.SelectFeature(iLayer, iFeature); m_NewPolygonFeedback = null; m_MapCtrls.ActiveView.Refresh(); } break; } case "rectangle": { IScreenDisplay iSDisplay = m_MapCtrls.ActiveView.ScreenDisplay; IPoint newPoint = new PointClass(); newPoint = iSDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); if (e.button == 1) { if (m_RecFeedback == null) { m_RecFeedback = new NewRectangleFeedbackClass(); m_RecFeedback.Display = iSDisplay; m_RecFeedback.Angle = 90; m_RecFeedback.Start(newPoint); newPoint.Y = newPoint.Y + 20; m_RecFeedback.SetPoint(newPoint); } else { m_RecFeedback.SetPoint(newPoint); } } if (e.button == 2) { if (m_RecFeedback != null) { m_NewPolygon = m_RecFeedback.Stop(newPoint) as IPolygon; //若是逆时针创建,反转一下,变为顺时针: IArea feedBackArea = m_NewPolygon as IArea; if (feedBackArea.Area < 0) { m_NewPolygon.ReverseOrientation(); } IGeometry newGeometry = m_NewPolygon as IGeometry; IFeatureWorkspace checkWorkspace = m_GlobalWorkspace as IFeatureWorkspace; IFeatureClass checkFeatureClass = checkWorkspace.OpenFeatureClass("CheckArea"); if (!(m_EditWorkspace.IsBeingEdited())) { m_EditWorkspace.StartEditing(false); } m_EditWorkspace.StartEditOperation(); int OID = CheckFeatueEditor.InsertNewFeature(newGeometry, checkFeatureClass, AppManager.GetInstance().TaskName); m_EditWorkspace.StopEditOperation(); ILayer iLayer = m_MapCtrls.Layer[0]; IFeature iFeature = checkFeatureClass.GetFeature(OID); clearFeatureSelection(); m_MapCtrls.Map.SelectFeature(iLayer, iFeature); m_MapCtrls.ActiveView.Refresh(); m_RecFeedback = null; } } break; } } #endregion }
public override void OnMouseDown(int int_0, int Shift, int int_2, int int_3) { if (int_0 != 1) { return; } IPoint mapPoint = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(int_2, int_3); ISnappingResult snappingResult = this.pointSnapper.Snap(mapPoint); if (anchorPoint == null) { anchorPoint = new AnchorPoint() { Symbol = simpleMarkerSymbol as ISymbol }; } if (snappingResult != null) { mapPoint = snappingResult.Location; // anchorPoint.MoveTo(mapPoint, activeView.ScreenDisplay); } if (_order == 0) { rectangleFeedback = new NewRectangleFeedback() as INewRectangleFeedback; rectangleFeedback.Display = activeView.ScreenDisplay; rectangleFeedback.Start(mapPoint); _order = 1; return; } if (_order == 1) { rectangleFeedback.SetPoint(mapPoint); //rectangleFeedback.Refresh(activeView.ScreenDisplay.hDC); _order = 2; return; } IPolygon rectangle = rectangleFeedback.Stop(mapPoint) as IPolygon; IFeatureLayer featureLayer = Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer; if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { IPointCollection polylineClass = new Polyline() as IPointCollection; object value = Missing.Value; IPointCollection segmentCollection = rectangle as IPointCollection; polylineClass.AddPointCollection(segmentCollection); CreateFeatureTool.CreateFeature(polylineClass as IGeometry, _context.FocusMap as IActiveView, Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer); } else if (featureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon) { return; } else { CreateFeatureTool.CreateFeature(rectangle as IGeometry, _context.FocusMap as IActiveView, Yutai.ArcGIS.Common.Editor.Editor.CurrentEditTemplate.FeatureLayer); } _order = 0; rectangleFeedback = null; }