//定义成员变量 private IActiveView pActiveView; private IMap pMap; private IWorkspaceEdit pWorkspaceEdit; private IPoint startPoint; private INewLineFeedback pLineFeedback; private IMoveGeometryFeedback pMoveGeometryFeedback; private ISet pMoveSet; public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (pMap.SelectionCount == 0) { MessageBox.Show("当前选择集为空,请选择要素!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (pWorkspaceEdit == null) return; if (!pWorkspaceEdit.IsBeingEdited()) return; startPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); if (pMoveGeometryFeedback == null) { IEnumFeature pEnumFeature = pMap.FeatureSelection as IEnumFeature; //QI if (pEnumFeature == null) return; //定义InvalidAreaClass对象,用于局部刷新数据 pInvalidArea = new InvalidAreaClass(); pInvalidArea.Display = pActiveView.ScreenDisplay; pInvalidArea.Add(pEnumFeature); pEnumFeature.Reset(); IFeature pFeature = pEnumFeature.Next(); //定义SetClass对象,用于存储当前要素选择集 pMoveSet = new SetClass(); pMoveGeometryFeedback = new MoveGeometryFeedbackClass(); pMoveGeometryFeedback.Display = pActiveView.ScreenDisplay; while (pFeature != null) { pMoveGeometryFeedback.AddGeometry(pFeature.Shape); pMoveSet.Add(pFeature); pFeature = pEnumFeature.Next(); } pMoveGeometryFeedback.Start(startPoint); } //定义NewLineFeedbackClass对象,用于显示要素移动的轨迹 if (pLineFeedback == null) { pLineFeedback = new NewLineFeedbackClass(); pLineFeedback.Display = pActiveView.ScreenDisplay; pLineFeedback.Start(startPoint); } } public override void OnMouseMove(int Button, int Shift, int X, int Y) { // TODO: Add MoveFeatures.OnMouseMove implementation if (startPoint == null) return; if (pLineFeedback == null || pMoveGeometryFeedback == null) return; IPoint pMouseMovePoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); pLineFeedback.MoveTo(pMouseMovePoint); pMoveGeometryFeedback.MoveTo(pMouseMovePoint); } public override void OnMouseUp(int Button, int Shift, int X, int Y) { // TODO: Add MoveFeatures.OnMouseUp implementation if (pMap.SelectionCount == 0) return; if (pLineFeedback == null || pMoveGeometryFeedback == null) return; if (startPoint == null) return; IPoint pEndPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); pLineFeedback.Stop(); pMoveGeometryFeedback.MoveTo(pEndPoint); if (startPoint.X != pEndPoint.X || startPoint.X != pEndPoint.Y) { MoveAllFeatures(pMoveSet, startPoint, pEndPoint); //局部刷新视图 pInvalidArea.Invalidate((short)esriScreenCache.esriAllScreenCaches); // pActiveView.Refresh(); } pLineFeedback = null; pMoveGeometryFeedback = null; } //定义MoveAllFeatures函数,用于移动要素集 private void MoveAllFeatures(ISet pMoveSet,IPoint pStartPoint, IPoint pEndPoint) { try { pWorkspaceEdit.StartEditOperation(); ILine pLine = new LineClass(); pLine.PutCoords(pStartPoint, pEndPoint); pLine.SpatialReference = pMap.SpatialReference; pMoveSet.Reset(); IFeatureEdit pFeatureEdit = pMoveSet.Next() as IFeatureEdit; while (pFeatureEdit != null) { pFeatureEdit.MoveSet(pMoveSet, pLine); pFeatureEdit = pMoveSet.Next() as IFeatureEdit; } pWorkspaceEdit.StopEditOperation(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
浙公网安备 33010602011771号