using SuperMap.Data; using System; using System.Collections.Generic; using System.Windows.Forms; using WWPipeLine.MapBasic.Conditions; using WWPipeLine.MapBasic; using System.Drawing; using SuperMap.UI; using SuperMap.Mapping; using System.Text; namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu { public class BZCheQi : BasicToolBar { private Point2D m_StartPoint = Point2D.Empty; private Point2D m_EndPoint = Point2D.Empty; private Selection[] _selection = null; private Recordset _recordset = null; private StringBuilder sb = new StringBuilder(); public BZCheQi() : base() { this.ConditionPanelName = "扯旗标注"; toolStripLB.Text = "鼠标左键点击选择需要标注的管线,再次点击完成标注。"; InitializeComponent(); } protected override void OnLoad(EventArgs e) { ComsStatic.SetLayersIsSelectableFalse(ComsStatic.dvJSLK.Name, true); MapControl.Action = SuperMap.UI.Action.Select; MapControl.MouseClick += MapControl_MouseClick; MapControl.MouseMove += MapControl_MouseMove; } private void MapControl_MouseMove(object sender, MouseEventArgs e) { if (m_StartPoint != Point2D.Empty) { m_EndPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y)); GeoLine geoLine = new GeoLine(new Point2Ds() { m_StartPoint, m_EndPoint }); geoLine.Style = ComsStatic.geoStyle_Brown_05mm; int index = MapControl.Map.TrackingLayer.IndexOf("MapControl_MouseMove"); if (index > -1) MapControl.Map.TrackingLayer.Remove(index); MapControl.Map.TrackingLayer.Add(geoLine, "MapControl_MouseMove"); MapControl.Map.RefreshTrackingLayer(); } } private void MapControl_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && MapControl.Action == SuperMap.UI.Action.Select && m_StartPoint == Point2D.Empty) { _selection = MapControl.Map.FindSelection(true); if (_selection is null || _selection.Length != 1) { Sunny.UI.UIMessageTip.ShowError("没有选中任何管线元素"); return; } _recordset = _selection[0].ToRecordset(); if (_recordset.RecordCount != 1) { Sunny.UI.UIMessageTip.ShowError("一次只可标记一条管线"); return; } QueryParameter queryParameter = new QueryParameter { AttributeFilter = string.Format(" pzlx='扯旗标注配置' AND gxlx='{0}' AND valueEnable=1 ", _recordset.Dataset.Name), ResultFields = new string[] { "pzKey", "valueBefore", "valueAfter" }, OrderBy = new string[] { " valueSort asc " }, CursorType = CursorType.Static }; Recordset rd = ComsStatic.dvJSLK_PZ.Query(queryParameter); if (rd.RecordCount == 0) { Sunny.UI.UIMessageTip.ShowError("选中的图层未配置标注字段信息"); return; } rd.MoveFirst(); sb.Clear(); while (!rd.IsEOF) { string ziduan = rd.GetFieldValue("pzKey").ToString(); if (ComsStatic.HasField(_recordset, ziduan)) { sb.AppendFormat("{0}:{1}{2}\r\n", rd.GetFieldValue("valueBefore"), _recordset.GetFieldValue(ziduan)?.ToString().Split('.')[0], rd.GetFieldValue("valueAfter")); } rd.MoveNext(); } m_StartPoint = _recordset.GetGeometry().InnerPoint; } else if (e.Button == MouseButtons.Left && m_StartPoint != Point2D.Empty && m_EndPoint != Point2D.Empty) { TextPart m_TextPart = new TextPart(); m_TextPart.AnchorPoint = m_EndPoint; m_TextPart.Text = sb.ToString(); GeoText geoText = new GeoText(m_TextPart, ComsStatic.BiaoZhuFengGe()); MapControl.Map.TrackingLayer.Add(geoText, "geoText"); GeoLine geoLine = new GeoLine(new Point2Ds() { m_StartPoint, m_EndPoint }); geoLine.Style = ComsStatic.geoStyle_Brown_05mm; MapControl.Map.TrackingLayer.Add(geoLine, "geoLine"); m_StartPoint = Point2D.Empty; m_EndPoint = Point2D.Empty; MapControl.Map.Refresh(); } } public override void AfterClose() { MapControl.MouseClick -= MapControl_MouseClick; MapControl.MouseMove -= MapControl_MouseMove; base.AfterClose(); } private void InitializeComponent() { this.SuspendLayout(); // // ToolsConditions // this.Name = "坐标标注"; this.ResumeLayout(false); } } }