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; namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu { public class BZMaiShen : BasicToolBar { private Point2D m_StartPoint = Point2D.Empty; private Point2D m_EndPoint = Point2D.Empty; private Recordset _recordset = null; public BZMaiShen() : base() { this.ConditionPanelName = "埋深标注"; InitializeComponent(); } protected override void OnLoad(EventArgs e) { MapControl.Action = SuperMap.UI.Action.Select; MapControl.MouseClick += MapControl_MouseClick; MapControl.MouseMove += MapControl_MouseMove; ComsStatic.SetLayersIsSelectableFalse(ComsStatic.gsGuanXian.Name, false); } 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[] _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; } m_StartPoint = _recordset.GetGeometry().InnerPoint; //m_StartPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y)); } 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 = "埋深:" + ComsStatic.StringToDouble(_recordset.GetFieldValue("ms"), 2).ToString() + "米"; m_TextPart.Text = "埋深:" + _recordset.GetDouble("ms") + "米"; 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"); MapControl.Map.RefreshTrackingLayer(); m_StartPoint = Point2D.Empty; m_EndPoint = Point2D.Empty; } } public override void AfterClose() { MapControl.MouseClick -= MapControl_MouseClick; MapControl.MouseMove -= MapControl_MouseMove; ComsStatic.RecordsetDispose(_recordset); base.AfterClose(); } private void InitializeComponent() { this.SuspendLayout(); // // ToolsConditions // this.ResumeLayout(false); } } }