private IPolygon GetBufferedSmallRings([NotNull] IPolyline tooSmallRings, double bufferDistance) { IList <IPolygon> bufferOutput = _bufferFactory.Buffer(tooSmallRings, bufferDistance); Assert.AreEqual(1, bufferOutput.Count, "Unexpected buffer output (distance: {0})", bufferDistance); IPolygon result = bufferOutput[0]; if (!((IZAware)result).ZAware) { tooSmallRings.QueryEnvelope(_envelopeTemplateBuffer); ((IZAware)result).ZAware = true; ((IZ)result).SetConstantZ(_envelopeTemplateBuffer.ZMin); } return(result); }
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); pt = GIS.GraphicEdit.SnapSetting.getSnapPoint(pt); 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.esriSLSSolid; simpleLineSymbol.Width = 2; simpleLineSymbol.Color = TransColorToAEColor(Color.Blue); m_NewLineFeedback.Start(pt); } else { m_NewLineFeedback.AddPoint(pt); } if (m_ptColl == null) { m_ptColl = new PolylineClass(); } //记录节点 object obj = Type.Missing; m_ptColl.AddPoint(pt, ref obj, ref obj); #endregion #region 绘制结点 try { IElement vertexElement = createElement_x(pt); // g = m_hookHelper.ActiveView as IGraphicsContainer; //g.AddElement(vertexElement, 0); //g.MoveElementToGroup(vertexElement, m_VertexElement); m_VertexElement.AddElement(vertexElement); //刷新 m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, vertexElement, pEnvBounds); } catch { } #endregion try { if (m_ptColl.PointCount >= 2) { IPoint fromPt = m_ptColl.get_Point(m_ptColl.PointCount - 2); //倒数第二个点 IPoint toPt = m_ptColl.get_Point(m_ptColl.PointCount - 1); //最后第一个点 ILine line = new LineClass(); line.PutCoords(fromPt, toPt); #region 绘制轨迹线 try { object missing = Type.Missing; ISegmentCollection segColl = new PolylineClass(); segColl.AddSegment(line as ISegment, ref missing, ref missing); IElement traceElement = createElement_x(segColl as IPolyline); // g = m_hookHelper.ActiveView as IGraphicsContainer; //g.AddElement(traceElement, 0); //g.MoveElementToGroup(traceElement, m_TraceElement); m_TraceElement.AddElement(traceElement); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, traceElement, pEnvBounds); } catch { } #endregion #region 计算单线的长度,并将结果显示在单线中点偏上上面 try { double angle = line.Angle; if ((angle > (Math.PI / 2) && angle < (Math.PI)) || (angle > -Math.PI && angle < -(Math.PI / 2))) // 大于90度小于等于180 { angle += Math.PI; } //标注点Y值偏移量 double d_OffsetY = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromPoints(9); //标注点 double d_CenterX = (fromPt.X + toPt.X) / 2; double d_CenterY = (fromPt.Y + toPt.Y) / 2 + d_OffsetY; //向上偏移 IPoint labelPt = new PointClass(); labelPt.PutCoords(d_CenterX, d_CenterY); IUnitConverter unitConverter = new UnitConverterClass(); double segmentLength = unitConverter.ConvertUnits(line.Length, _MsgInfo.inUnit.pUnit, _MsgInfo.outUnit.pUnit); ITextElement txtElement = CreateTextElement(segmentLength.ToString("0.00")); IElement labelelement = txtElement as IElement; labelelement.Geometry = labelPt; object oElement = (object)labelelement; //根据角度旋转 TransformByRotate(ref oElement, labelPt, angle); ////添加到GraphicsContainer //g.AddElement(labelelement, 0); ////移到m_LabelElement组中 //g.MoveElementToGroup(labelelement, m_LabelElement); //添加到组 m_LabelElement.AddElement(labelelement); //刷新 m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, labelelement, pEnvBounds); } catch { } #endregion } } catch { } _MsgInfo.LineResultChange(); }