这里只给出主要的功能代码,实现了移动选定点,当然还可以扩展实现以线和面。
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
if (m_CurrentLayer == null)//m_CurrentLayer 是IFeatureLayer
return;
if ((m_CurrentLayer as IGeoFeatureLayer) == null) return;
featureLayer = m_CurrentLayer as IFeatureLayer;
IFeatureClass featureClass = featureLayer.FeatureClass;
if (featureClass == null) return;
// 检查是否有要素被选中,没有则MessageBox提醒
IFeatureSelection pFeatSel = (IFeatureSelection)m_CurrentLayer;
ISelectionSet pSelectionSet = pFeatSel.SelectionSet;
if (pSelectionSet.Count == 0)
{
MessageBox.Show("在 '" + m_CurrentLayer.Name + "' 图层没有要素被选中!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
// 有则返回要素游标
ICursor pCursor1;
pSelectionSet.Search(null, false, out pCursor1);
IFeatureCursor featureCursor = pCursor1 as IFeatureCursor;
newfeature = featureCursor.NextFeature();
IGeometry startGeom = newfeature.Shape;
IPoint point = m_ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
try
{
switch (featureClass.ShapeType)
{
case esriGeometryType.esriGeometryPoint:
m_FeedBack = new MovePointFeedbackClass();
m_FeedBack.Display = m_ActiveView.ScreenDisplay;
IMovePointFeedback pointMoveFeedback = m_FeedBack as IMovePointFeedback;
pointMoveFeedback.Start(startGeom as IPoint, point);
break;
default:
break;
}
}
catch
{
MessageBox.Show("请检查代码!");
return;
}
}
public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
IPoint point = m_ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
m_FeedBack.MoveTo(point);
}
public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
m_DisplayGeometry = EndFeatureMove(X, Y);
//UpdateEdit(m_DisplayGeometry);
//IFeature point =null ;
point = m_CurrentLayer.FeatureClass.CreateFeature();
point.Shape = m_DisplayGeometry;
point.Store();
newfeature.Delete();
m_Map.ClearSelection();
IFeatureSelection feaSelect = featureLayer as IFeatureSelection;
feaSelect.SelectionSet.Add(point.OID);
//m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGraphicSelection, null, m_ActiveView.Extent);
m_ActiveView.Refresh();
}
public IGeometry EndFeatureMove(int x, int y)
{
if (m_FeedBack == null) return null;
IGeometry geometry = null;
try
{
if ((m_FeedBack as IMovePointFeedback) != null)
{
IMovePointFeedback pointMoveFeedback = m_FeedBack as IMovePointFeedback;
geometry = pointMoveFeedback.Stop();
}
}
catch { return null; }
m_FeedBack = null;
return geometry;
}