LayerWithDataListPanel.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using Sunny.UI;
  2. using SuperMap.Data;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Windows.Forms;
  6. using SuperMap.Mapping;
  7. using SuperMap.UI;
  8. namespace WWPipeLine.MapBasic
  9. {
  10. /// <summary>
  11. /// 数据图层列表:用于显示场景中的图层。
  12. /// </summary>
  13. public class LayerWithDataListPanel : Sunny.UI.UIFlowLayoutPanel
  14. {
  15. public LayerWithDataListPanel() : base()
  16. {
  17. InitializeComponent();
  18. this.Text = "LayerWithDataListPanel";
  19. this.Dock = DockStyle.Fill;
  20. this.RectSides = ToolStripStatusLabelBorderSides.None;//边框显示位置 没有边框
  21. this.RadiusSides = UICornerRadiusSides.None;//圆角显示位置 没有圆角
  22. this.ParentChanged += LayerWithDataListPanel_ParentChanged;
  23. }
  24. /// <summary>
  25. /// 设置当前控件的外观Padding
  26. /// </summary>
  27. /// <param name="sender"></param>
  28. /// <param name="e"></param>
  29. private void LayerWithDataListPanel_ParentChanged(object sender, EventArgs e)
  30. {
  31. if (this.Parent == null) return;
  32. if (this.Parent is UIGroupBox)
  33. {
  34. var ugb = this.Parent as UIGroupBox;
  35. ugb.Padding = new Padding(6, ugb.Padding.Top, 6, 4);
  36. }
  37. }
  38. private MapControl m_MapControl;
  39. //public MapControl MapControl { get => m_MapControl; }
  40. /// <summary>
  41. /// 初始化
  42. /// </summary>
  43. /// <param name="mp"></param>
  44. public void Init(MapControl mp)
  45. {
  46. m_MapControl = mp;
  47. }
  48. /// <summary>
  49. /// 加载矢量图层列表
  50. /// </summary>
  51. /// <param name="multiSelect"></param>
  52. public virtual void LoadToVector(bool multiSelect = false)
  53. {
  54. var types = new List<DatasetType>()
  55. {
  56. DatasetType.Point,
  57. DatasetType.Line,
  58. DatasetType.Region,
  59. DatasetType.Network,
  60. };
  61. foreach (Layer lyr in m_MapControl.Map.Layers)
  62. {
  63. var name = lyr.Name;
  64. var text = lyr.Caption;
  65. var dataset = lyr.Dataset;
  66. if (dataset == null) continue;//图层数据集为NULL时,直接跳过
  67. if (!types.Contains(dataset.Type)) continue;
  68. AddBtnInter(name, text, lyr, multiSelect);
  69. }
  70. }
  71. /// <summary>
  72. /// 加载按钮。根据multiSelect判断是UICheckBox或者UIRadioButton
  73. /// </summary>
  74. /// <param name="name"></param>
  75. /// <param name="text"></param>
  76. /// <param name="lyr"></param>
  77. /// <param name="multiSelect"></param>
  78. private void AddBtnInter(string name, string text, Layer lyr, bool multiSelect = false)
  79. {
  80. if (multiSelect)
  81. {
  82. Sunny.UI.UICheckBox cBtn = new UICheckBox()
  83. {
  84. Name = name,
  85. Text = text,
  86. Tag = lyr,
  87. Location = new System.Drawing.Point(20, 40 + this.Controls.Count * 28),
  88. Width = 300
  89. };
  90. this.Add(cBtn);
  91. cBtn.ValueChanged += CBtn_ValueChanged;
  92. }
  93. else
  94. {
  95. Sunny.UI.UIRadioButton rBtn = new UIRadioButton()
  96. {
  97. Name = name,
  98. Text = text,
  99. Tag = lyr,
  100. Location = new System.Drawing.Point(20, 40 + this.Controls.Count * 28),
  101. Width = 300
  102. };
  103. this.Add(rBtn);
  104. rBtn.ValueChanged += RBtn_ValueChanged;
  105. }
  106. }
  107. private void CBtn_ValueChanged(object sender, bool value)
  108. {
  109. var cBtn = sender as UICheckBox;
  110. if (cBtn.Checked)
  111. {
  112. m_SelectLayerDatasetVectors.Add(cBtn.Tag as DatasetVector);
  113. }
  114. else
  115. {
  116. m_SelectLayerDatasetVectors.Remove(cBtn.Tag as DatasetVector);
  117. }
  118. }
  119. private void RBtn_ValueChanged(object sender, bool value)
  120. {
  121. var rBtn = sender as UIRadioButton;
  122. if (!rBtn.Checked) return;
  123. m_SelectLayerDatasetVector = rBtn.Tag as DatasetVector;
  124. m_SelectLayerName = rBtn.Name as string;
  125. }
  126. private string m_SelectLayerName;
  127. /// <summary>
  128. /// 获取LayerWithDataListPanel中UIRadioButton的选择项,通过选择项Tag转为Layer
  129. /// <para>此处的Layer只能是一个。只能按照一个图层去查询。</para>
  130. /// </summary>
  131. public string SelectLayerName { get => m_SelectLayerName; }
  132. private DatasetVector m_SelectLayerDatasetVector;
  133. /// <summary>
  134. /// 获取LayerWithDataListPanel中UIRadioButton的选择项,通过选择项Tag转为DatasetVector
  135. /// </summary>
  136. public DatasetVector SelectLayerDatasetVector { get => m_SelectLayerDatasetVector; }
  137. List<DatasetVector> m_SelectLayerDatasetVectors = new List<DatasetVector>();
  138. /// <summary>
  139. /// 获取获取LayerWithDataListPanel中UICheckBox的选择项集合,通过选择项Tag转为List<DatasetVector>
  140. /// </summary>
  141. public List<DatasetVector> SelectLayerDatasetVectors { get => m_SelectLayerDatasetVectors; }
  142. private void InitializeComponent()
  143. {
  144. this.SuspendLayout();
  145. //
  146. // LayerWithDataListPanel
  147. //
  148. this.Name = "LayerWithDataListPanel";
  149. this.Size = new System.Drawing.Size(271, 387);
  150. this.ResumeLayout(false);
  151. }
  152. }
  153. }