/// <summary> /// 测量工具 /// </summary> internal MeasureTools(AxMapControl mapCtrl) { MapCtrl = mapCtrl; _pointCollection = null; _newPolygonFeedback = null; _newLineFeedback = null; _eMeasureType = 0; IsSurveying = false; }
/// <summary> /// 地图测量操作 /// </summary> public MapCtrlMeasure(AxMapControl mapCtrl) { MapControl = mapCtrl; _pointCollection = null; _newPolygonFeedback = null; _newLineFeedback = null; _eMeasureType = EMeasureType.None; AreaPointCount = 0; IsSurveying = false; }
/// <summary> /// 开始测角度,point为折线起点,测量结果为 /// Direction:当前线段的方向角,即与正北方向的夹角 /// Angle:当前线段与前一线段的夹角 /// 在Map的MouseDown事件中调用本方法 /// </summary> /// <param name="point">折线起点</param> public void AngleStart(IPoint point) { _eMeasureType = EMeasureType.Angle; _newLineFeedback = new NewLineFeedbackClass { Display = MapCtrl.ActiveView.ScreenDisplay }; _newLineFeedback.Start(point); _pointCollection = new PolylineClass(); object ep = System.Reflection.Missing.Value; _pointCollection.AddPoint(point, ref ep, ref ep); IsSurveying = true; }
/// <summary> /// 开始面积测量,point为多边形起点 /// </summary> /// <param name="point">测量起点</param> public void AreaStart(IPoint point) { _eMeasureType = EMeasureType.Area; _newPolygonFeedback = new NewPolygonFeedbackClass { Display = MapControl.ActiveView.ScreenDisplay }; _newPolygonFeedback.Start(point); _pointCollection = new PolygonClass(); object ep = System.Reflection.Missing.Value; _pointCollection.AddPoint(point, ref ep, ref ep); IsSurveying = true; AreaPointCount = 1; }
private double MeasureText(DrawingContext dc, string txtInfo, EMeasureType measureType) { double txtWidth = 0.0; switch (measureType) { case EMeasureType.MeasureHeader: txtWidth = this.MeasureHeaderText(dc, txtInfo); break; case EMeasureType.MeasureFooter: txtWidth = this.MeasureFooterText(dc, txtInfo); break; default: case EMeasureType.MeasureNormal: txtWidth = this.MeasureNormalText(dc, txtInfo); break; } return txtWidth; }
protected string SplitFilePath(string filePath, Rect region, DrawingContext dc, EMeasureType measerHeader) { // eg: D:\...\CPCFC1.CFC; if (string.IsNullOrEmpty(filePath)) return filePath; filePath = filePath.Trim(new char[]{' ', '\\'}); int startIndex = filePath.IndexOf('\\'); int lastIndex = filePath.LastIndexOf('\\'); if (startIndex <= 0 || lastIndex <= 0) return filePath; string prefix = filePath.Substring(0, startIndex + 1); string suffix = filePath.Substring(lastIndex); string splitContent = filePath.Substring(startIndex + 1, lastIndex - startIndex - 1); double prefixWidth = this.MeasureText(dc, prefix, measerHeader); double suffixWidth = this.MeasureText(dc, suffix, measerHeader); if (prefixWidth > region.Width) return prefix + "..."; else if (prefixWidth + suffixWidth > region.Width) return prefix + this.splitFromLeft(suffix, region.Width - prefixWidth, dc, measerHeader); else return prefix + this.splitFromRight(splitContent, region.Width - prefixWidth - suffixWidth, dc, measerHeader) + suffix; }
/// <summary> /// 对drawHeaderText与drawFooterText函数进行了封装,当字符串过长的时候,可以进行相关的字符串截取操作; /// </summary> private void drawText(DrawingContext dc, string text, Rect rcText, HorizontalAlignment hAlign, string regType, EMeasureType drawHeader) { try { if (this.IsOnlyFilePath(regType)) text = this.SplitFilePath(text, rcText, dc, drawHeader); else text = this.splitFromRight(text, rcText.Width, dc, drawHeader); if (drawHeader == EMeasureType.MeasureHeader) this.drawHeaderText(dc, text, rcText, hAlign); else if (drawHeader == EMeasureType.MeasureFooter) this.drawFooterText(dc, text, rcText, hAlign); else this.drawNormalText(dc, text, rcText, hAlign); } catch (Exception ee) { Trace.WriteLine("### [" + ee.Source + "] Exception: " + ee.Message); Trace.WriteLine("### " + ee.StackTrace); } }