123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- 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 BZShiTi : BasicToolBar
- {
- private Point2D m_StartPoint = Point2D.Empty;
- private Point2D m_EndPoint = Point2D.Empty;
- private Selection[] _selection = null;
- private Recordset _recordset = null;
- private string _str;
- public BZShiTi() : base()
- {
- this.ConditionPanelName = "单一实体标注";
- InitializeComponent();
- }
- protected override void OnLoad(EventArgs e)
- {
- 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.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)
- {
- Sunny.UI.UIMessageTip.ShowError("选中的节点没有数据"); return;
- }
- DatasetVector dv = _recordset.Dataset as DatasetVector;
- if (dv.Name == dvJSLK_cp.Name)
- {
- if (!ComsStatic.HasField(dv, "cd"))
- { Sunny.UI.UIMessageTip.ShowError("当前管线没有长度信息"); return; }
- _str = "L=" + ComsStatic.StringToDouble(_recordset.GetFieldValue("cd"), 2).ToString() + "米";
- }
- else
- {
- if (!ComsStatic.HasField(dv, "x") || !ComsStatic.HasField(dv, "y"))
- { Sunny.UI.UIMessageTip.ShowError("当前管点没有坐标数据"); return; }
- _str = string.Format("X:{0}\r\nY:{1}", ComsStatic.StringToDouble(_recordset.GetFieldValue("x"), 2).ToString(), ComsStatic.StringToDouble(_recordset.GetFieldValue("y"), 2).ToString());
- }
- 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 = _str;
- 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);
- }
- }
- }
|