ArcEngine 测量 docx 下载本文

/// Occurs when this tool is created ///

/// public override void OnCreate(object hook) { try {

m_hookHelper = new HookHelperClass(); m_hookHelper.Hook = hook;

if (m_hookHelper.ActiveView == null) {

m_hookHelper = null; } } catch {

m_hookHelper = null; }

if (m_hookHelper == null) base.m_enabled = false; else

base.m_enabled = true;

// TODO: Add other initialization code }

void Init() {

//初始化

m_Elements = new GroupElementClass(); m_TraceElement = new GroupElementClass();

m_VertexElement = new GroupElementClass(); m_LabelElement = new GroupElementClass();

//初始化,并添加到GraphicsContainer

IGraphicsContainer g = m_hookHelper.ActiveView as IGraphicsContainer;

g.AddElement(m_Elements as IElement, 0); g.AddElement(m_TraceElement as IElement, 0); g.AddElement(m_VertexElement as IElement, 0); g.AddElement(m_LabelElement as IElement, 0);

//添加到m_Elements中

g.MoveElementToGroup(m_VertexElement as IElement, m_Elements);

g.MoveElementToGroup(m_LabelElement as IElement, m_Elements);

g.MoveElementToGroup(m_TraceElement as IElement, m_Elements); }

///

/// Occurs when this tool is clicked ///

public override void OnClick() {

Init(); }

void msgInfo_FromClosing(object sender, FormClosingEventArgs e) {

DeleteAllElements(); _MsgInfo = null;

//throw new Exception(\lemented.\ }

public override void OnMouseDown(int Button, int Shift, int X, int Y) {

if (Button == 2) return;

IPoint pt = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

IGraphicsContainer g = m_hookHelper.ActiveView.GraphicsContainer;

IEnvelope pEnvBounds = null;

//获取上一次轨迹线的范围,以便确定刷新范围 try {

if (m_TraceLine != null) {

m_TraceLine.QueryEnvelope(pEnvBounds);

pEnvBounds.Expand(4, 4, true); //矩形框向四周扩大4倍(大于2倍就行),目的是为了保证有充足的刷新区域 } else

pEnvBounds = m_hookHelper.ActiveView.Extent; } catch {

pEnvBounds = m_hookHelper.ActiveView.Extent; }

#region 启动画线

if (m_NewLineFeedback == null) {

//移除element RemoveElements(); //刷新

m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); Application.DoEvents();

m_NewLineFeedback = new NewLineFeedbackClass(); m_NewLineFeedback.Display = m_hookHelper.ActiveView.ScreenDisplay;

//必须先得到symbol,后设置symbol

ISimpleLineSymbol simpleLineSymbol = m_NewLineFeedback.Symbol as ISimpleLineSymbol;

simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDot;

simpleLineSymbol.Width = 1;

simpleLineSymbol.Color = TransColorToAEColor(Color.Blue);

m_NewLineFeedback.Start(pt); } else {

m_NewLineFeedback.AddPoint(pt); }

if (m_ptColl == null) {