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 WWPipeLine.MapBasic; using SuperMap.Mapping; namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu { public class BZMaiShen : BasicToolBar { private Point2D m_StartPoint = Point2D.Empty; private Point2D m_EndPoint = Point2D.Empty; private Selection[] _selection = null; private Recordset _recordset = null; public BZMaiShen() : base() { this.ConditionPanelName = "埋深标注"; this.toolStripLB.Text = "先选择管点,再右键绘制"; InitializeComponent(); } protected override void OnLoad(EventArgs e) { MapControl.Action = SuperMap.UI.Action.Select; MapControl.MouseClick += MapControl_MouseClick; MapControl.MouseMove += MapControl_MouseMove; ComsStatic.SetLayersIsSelectableFalse(ComsStatic.dvJSLK.Name, true); } 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.Refresh(); } } 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 || !ComsStatic.HasField(_recordset, "ms")) { Sunny.UI.UIMessageTip.ShowError("选中的节点没有埋深数据"); return; } m_StartPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y)); MapControl.Action = SuperMap.UI.Action.Pan; MapControl.Map.Refresh(); } else if (e.Button == MouseButtons.Left && m_StartPoint != Point2D.Empty && m_EndPoint != Point2D.Empty) { TextPart m_TextPart = new TextPart(); m_TextPart.X = m_EndPoint.X; m_TextPart.Y = m_EndPoint.Y; m_TextPart.Text = "埋深:" + ComsStatic.StringToDouble(_recordset.GetFieldValue("ms"), 2).ToString() + "米"; GeoText geoText = new GeoText(m_TextPart, ComsStatic.textStyle_Brown_6mm_BottomLeft); 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); } } }