BZZuoBiao.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using SuperMap.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Windows.Forms;
  5. using WWPipeLine.MapBasic.Conditions;
  6. using WWPipeLine.MapBasic;
  7. using System.Drawing;
  8. using SuperMap.UI;
  9. namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu
  10. {
  11. public class BZZuoBiao : BasicToolBar
  12. {
  13. private Point2D m_StartPoint = Point2D.Empty;
  14. private Point2D m_EndPoint = Point2D.Empty;
  15. public BZZuoBiao() : base()
  16. {
  17. this.ConditionPanelName = "坐标标注";
  18. InitializeComponent();
  19. toolStripLB.Text = "鼠标左键点击选择标注点,再次点击完成标注。";
  20. }
  21. protected override void OnLoad(EventArgs e)
  22. {
  23. MapControl.Action = SuperMap.UI.Action.CreateLine;
  24. MapControl.Tracked += new TrackedEventHandler(MapControl_Tracked);
  25. MapControl.Tracking += new TrackingEventHandler(MapControl_Tracking);
  26. }
  27. private void MapControl_Tracking(object sender, TrackingEventArgs e)
  28. {
  29. if (m_StartPoint == Point2D.Empty)
  30. m_StartPoint = new Point2D(e.X, e.Y);
  31. else
  32. m_EndPoint = new Point2D(e.X, e.Y);
  33. }
  34. private void MapControl_Tracked(object sender, TrackedEventArgs e)
  35. {
  36. if (m_StartPoint != Point2D.Empty && m_EndPoint != Point2D.Empty)
  37. {
  38. TextPart m_TextPart = new TextPart();
  39. m_TextPart.AnchorPoint = m_EndPoint;
  40. m_TextPart.Text = string.Format("X:{0}\r\nY:{1}", Math.Round(m_StartPoint.X, 2), Math.Round(m_StartPoint.Y, 2));
  41. GeoText geoText = new GeoText(m_TextPart, ComsStatic.BiaoZhuFengGe());
  42. MapControl.Map.TrackingLayer.Add(geoText, "geoText");
  43. Point2D p3 = new Point2D(geoText.Bounds.Right, geoText.Bounds.Bottom);
  44. //此处调试geoText.Bounds 左右、上下端点几乎一致 但是实际上界面是有XY坐标显示额
  45. //geoText.Bounds.Left 833130.131007001
  46. //geoText.Bounds.Right 833130.131007401
  47. //geoText.Bounds.Top 5051136.9966243524
  48. //geoText.Bounds.Bottom 5051136.9966239519
  49. GeoLine geoLine = new GeoLine();
  50. geoLine.AddPart(new Point2Ds() { m_StartPoint, m_EndPoint, p3 });
  51. geoLine.Style = ComsStatic.geoStyle_Brown_05mm;
  52. MapControl.Map.TrackingLayer.Add(geoLine, "geoLine");
  53. m_StartPoint = Point2D.Empty; m_EndPoint = Point2D.Empty;
  54. MapControl.Map.Refresh();
  55. }
  56. }
  57. public override void AfterClose()
  58. {
  59. MapControl.Tracked -= MapControl_Tracked;
  60. MapControl.Tracking -= MapControl_Tracking;
  61. base.AfterClose();
  62. }
  63. private void InitializeComponent()
  64. {
  65. this.SuspendLayout();
  66. //
  67. // ToolsConditions
  68. //
  69. this.ResumeLayout(false);
  70. }
  71. }
  72. }