主要修改的地方为在绘制过程中或绘制结束后实现了结点的符号化,效果如图:
![AE画线](https://www.cnblogs.com/images/cnblogs_com/jindin/未命名.JPG)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
利用INewLineFeedback画线
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using System.Windows.Forms;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace CHD.GIS.myCommands
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public sealed class myAddPolyLine : BaseTool
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private IHookHelper m_hookHelper;
private INewLineFeedback m_LineFeedback;
public myAddPolyLine()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//
// TODO: Define values for the public properties
//
base.m_category = ""; //localizable text
base.m_caption = "添加线"; //localizable text
base.m_message = ""; //localizable text
base.m_toolTip = ""; //localizable text
base.m_name = ""; //unique id, non-localizable (e.g. "MyCategory_MyTool")
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//
// TODO: change resource name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur");
}
catch (Exception ex)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
Overriden Class Methods#region Overriden Class Methods
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// Occurs when this tool is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (m_hookHelper == null)
m_hookHelper = new HookHelperClass();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
m_hookHelper.Hook = hook;
// TODO: Add myAddLine.OnCreate implementation
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// Occurs when this tool is clicked
/// </summary>
public override void OnClick()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// TODO: Add myAddLine.OnClick implementation
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public override void OnMouseDown(int Button, int Shift, int X, int Y)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (Button == 2) //右键
return;
// TODO: Add myAddLine.OnMouseDown implementation
IPoint pt = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
if (m_LineFeedback == null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_LineFeedback = new NewLineFeedbackClass();
m_LineFeedback.Display = m_hookHelper.ActiveView.ScreenDisplay;
m_LineFeedback.Start(pt);
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_LineFeedback.AddPoint(pt);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
绘制结点的第一种方法,在绘制过程中添加结点符号,效果类似于画线编辑时的效果#region 绘制结点的第一种方法,在绘制过程中添加结点符号,效果类似于画线编辑时的效果
//设置结点符号
IRgbColor pRGB = new RgbColorClass();
pRGB.Red = 255;
pRGB.Green = 0;
pRGB.Blue = 0;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ISimpleMarkerSymbol pSimpleMarkSymbol = new SimpleMarkerSymbolClass();
pSimpleMarkSymbol.Color = pRGB as IColor;
pSimpleMarkSymbol.Size = 4;
pSimpleMarkSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
IMarkerElement pMarkerElement = new MarkerElementClass();
pMarkerElement.Symbol = pSimpleMarkSymbol as IMarkerSymbol;
IElement ele = pMarkerElement as IElement;
ele.Geometry = pt as IGeometry;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//获取结点element的范围,以便确定刷新范围
IEnvelope pEnvBounds=new EnvelopeClass();
ele.QueryBounds(m_hookHelper.ActiveView.ScreenDisplay as IDisplay,pEnvBounds);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
IGraphicsContainer pGra = m_hookHelper.ActiveView as IGraphicsContainer;
pGra.AddElement(ele, 0);
m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,ele, pEnvBounds); //局部刷新,第二次参数必须是ele,如果是null,画线过程中线就没了,被刷新没了.
#endregion
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public override void OnMouseMove(int Button, int Shift, int X, int Y)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// TODO: Add myAddLine.OnMouseMove implementation
if (m_LineFeedback == null)
return;
IPoint pt = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
m_LineFeedback.MoveTo(pt);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public override void OnMouseUp(int Button, int Shift, int X, int Y)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
public override void OnDblClick()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
IPolyline pPolyline=null;
IGroupElement pGroupElement = new GroupElementClass();
try
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (m_LineFeedback == null)
return;
pPolyline = m_LineFeedback.Stop();
if (pPolyline == null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
m_LineFeedback = null;
return;
}
//设置线型
IRgbColor pRGB = new RgbColorClass();
pRGB.Red = 0;
pRGB.Green = 120;
pRGB.Blue = 0;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ISimpleLineSymbol pSimplelineSymbol = new SimpleLineSymbolClass();
pSimplelineSymbol.Color = pRGB as IColor;
pSimplelineSymbol.Width = 1.5;
pSimplelineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//m_LineFeedback.Symbol = pSimplelineSymbol as ISymbol;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ILineElement pLineElement = new LineElementClass();
pLineElement.Symbol = pSimplelineSymbol as ILineSymbol;
IElement element = pLineElement as IElement;
element.Geometry = pPolyline as IGeometry;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
pGroupElement.AddElement(element);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
绘制结点的第二种方法,全部结束时绘制结点#region 绘制结点的第二种方法,全部结束时绘制结点
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/////设置结点符号
//pRGB = new RgbColorClass();
//pRGB.Red = 255;
//pRGB.Green = 0;
//pRGB.Blue = 0;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//ISimpleMarkerSymbol pSimpleMarkSymbol = new SimpleMarkerSymbolClass();
//pSimpleMarkSymbol.Color = pRGB as IColor;
//pSimpleMarkSymbol.Size = 4;
//pSimpleMarkSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**/////获取得到结点
//IPointCollection pPointCol = (IPointCollection)pPolyline;
//for(int index =0;index<pPointCol.PointCount;index++)
//{
// IPoint pt = pPointCol.get_Point(index);
// IMarkerElement pMarkerElement = new MarkerElementClass();
// pMarkerElement.Symbol = pSimpleMarkSymbol as IMarkerSymbol;
// IElement ele = pMarkerElement as IElement;
// ele.Geometry = pt as IGeometry;
// pGroupElement.AddElement(ele);
//}
#endregion
}
catch (Exception ex)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
return;
}
finally
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
IGraphicsContainer pGraphicsContainer = m_hookHelper.ActiveView as IGraphicsContainer;
pGraphicsContainer.AddElement(pGroupElement as IElement, ((IPointCollection)pPolyline).PointCount);
m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pGroupElement,pPolyline.Envelope);
//释放变量
m_LineFeedback = null;
}
}
#endregion
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)