using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
namespace test1023
{
public partial class Form1 : Form
{
private IActiveView pActiveView;
private IMap pMap;
private IWorkspaceEdit pWorkspaceEdit;
private IPoint startPoint;
private INewLineFeedback pLineFeedback;
private IMoveGeometryFeedback pMoveGeometryFeedback;
private ISet pMoveSet;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.axMapControl1.OnMouseDown += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseDownEventHandler(defaultMapControl_OnMouseDown);
this.axMapControl1.OnMouseMove += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseMoveEventHandler(defaultMapControl_OnMouseMove);
this.axMapControl1.OnMouseUp += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseUpEventHandler(defaultMapControl_OnMouseUp);
}
private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
//if (this.axMapControl1.CurrentTool != null)
//{
// return;
//}
//pActiveView = this.axMapControl1.ActiveView;
//pMap = this.axMapControl1.Map;
//startPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
//if (pMoveGeometryFeedback == null)
//{
// IEnumFeature pEnumFeature = pMap.FeatureSelection as IEnumFeature;
// 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);
//}
}
private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
{
//if (this.axMapControl1.CurrentTool != null)
//{
// return;
//}
//if (startPoint == null)
// return;
//if (pLineFeedback == null || pMoveGeometryFeedback == null)
// return;
//IPoint pMouseMovePoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
//pLineFeedback.MoveTo(pMouseMovePoint);
//pMoveGeometryFeedback.MoveTo(pMouseMovePoint);
}
private void axMapControl1_OnMouseUp(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseUpEvent e)
{
//if (this.axMapControl1.CurrentTool != null)
//{
// return;
//}
//if (pLineFeedback == null || pMoveGeometryFeedback == null)
// return;
//if (startPoint == null)
// return;
//IPoint pEndPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
//pLineFeedback.Stop();
//pMoveGeometryFeedback.MoveTo(pEndPoint);
//if (startPoint.X != pEndPoint.X || startPoint.X != pEndPoint.Y)
//{
// MoveAllFeatures(pMoveSet, startPoint, pEndPoint);
// this.axMapControl1.Refresh();
//}
//pLineFeedback = null;
//pMoveGeometryFeedback = null;
}
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);
}
}
private void button1_Click(object sender, EventArgs e)
{
this.axMapControl1.CurrentTool = null;
}
//------------
private void defaultMapControl_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
if (this.axMapControl1.CurrentTool != null)
{
return;
}
pActiveView = this.axMapControl1.ActiveView;
pMap = this.axMapControl1.Map;
startPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
if (pMoveGeometryFeedback == null)
{
IEnumFeature pEnumFeature = pMap.FeatureSelection as IEnumFeature;
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);
}
}
private void defaultMapControl_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
{
if (this.axMapControl1.CurrentTool != null)
{
return;
}
if (startPoint == null)
return;
if (pLineFeedback == null || pMoveGeometryFeedback == null)
return;
IPoint pMouseMovePoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
pLineFeedback.MoveTo(pMouseMovePoint);
pMoveGeometryFeedback.MoveTo(pMouseMovePoint);
}
private void defaultMapControl_OnMouseUp(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseUpEvent e)
{
if (this.axMapControl1.CurrentTool != null)
{
return;
}
if (pLineFeedback == null || pMoveGeometryFeedback == null)
return;
if (startPoint == null)
return;
IPoint pEndPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
pLineFeedback.Stop();
pMoveGeometryFeedback.MoveTo(pEndPoint);
if (startPoint.X != pEndPoint.X || startPoint.X != pEndPoint.Y)
{
MoveAllFeatures(pMoveSet, startPoint, pEndPoint);
this.axMapControl1.Refresh();
}
pLineFeedback = null;
pMoveGeometryFeedback = null;
}
}
}