using Sunny.UI;
using SuperMap.Data;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using SuperMap.Mapping;
using SuperMap.UI;
namespace WWPipeLine.MapBasic
{
///
/// 数据图层列表:用于显示场景中的图层。
///
public class LayerWithDataListPanel : Sunny.UI.UIFlowLayoutPanel
{
public LayerWithDataListPanel() : base()
{
InitializeComponent();
this.Text = "LayerWithDataListPanel";
this.Dock = DockStyle.Fill;
this.RectSides = ToolStripStatusLabelBorderSides.None;//边框显示位置 没有边框
this.RadiusSides = UICornerRadiusSides.None;//圆角显示位置 没有圆角
this.ParentChanged += LayerWithDataListPanel_ParentChanged;
}
///
/// 设置当前控件的外观Padding
///
///
///
private void LayerWithDataListPanel_ParentChanged(object sender, EventArgs e)
{
if (this.Parent == null) return;
if (this.Parent is UIGroupBox)
{
var ugb = this.Parent as UIGroupBox;
ugb.Padding = new Padding(6, ugb.Padding.Top, 6, 4);
}
}
private MapControl m_MapControl;
//public MapControl MapControl { get => m_MapControl; }
///
/// 初始化
///
///
public void Init(MapControl mp)
{
m_MapControl = mp;
}
///
/// 加载矢量图层列表
///
///
public virtual void LoadToVector(bool multiSelect = false)
{
var types = new List()
{
DatasetType.Point,
DatasetType.Line,
DatasetType.Region,
DatasetType.Network,
};
foreach (Layer lyr in m_MapControl.Map.Layers)
{
var name = lyr.Name;
var text = lyr.Caption;
var dataset = lyr.Dataset;
if (dataset == null) continue;//图层数据集为NULL时,直接跳过
if (!types.Contains(dataset.Type)) continue;
AddBtnInter(name, text, lyr, multiSelect);
}
}
///
/// 加载按钮。根据multiSelect判断是UICheckBox或者UIRadioButton
///
///
///
///
///
private void AddBtnInter(string name, string text, Layer lyr, bool multiSelect = false)
{
if (multiSelect)
{
Sunny.UI.UICheckBox cBtn = new UICheckBox()
{
Name = name,
Text = text,
Tag = lyr,
Location = new System.Drawing.Point(20, 40 + this.Controls.Count * 28),
Width = 300
};
this.Add(cBtn);
cBtn.ValueChanged += CBtn_ValueChanged;
}
else
{
Sunny.UI.UIRadioButton rBtn = new UIRadioButton()
{
Name = name,
Text = text,
Tag = lyr,
Location = new System.Drawing.Point(20, 40 + this.Controls.Count * 28),
Width = 300
};
this.Add(rBtn);
rBtn.ValueChanged += RBtn_ValueChanged;
}
}
private void CBtn_ValueChanged(object sender, bool value)
{
var cBtn = sender as UICheckBox;
if (cBtn.Checked)
{
m_SelectLayerDatasetVectors.Add(cBtn.Tag as DatasetVector);
}
else
{
m_SelectLayerDatasetVectors.Remove(cBtn.Tag as DatasetVector);
}
}
private void RBtn_ValueChanged(object sender, bool value)
{
var rBtn = sender as UIRadioButton;
if (!rBtn.Checked) return;
m_SelectLayerDatasetVector = rBtn.Tag as DatasetVector;
m_SelectLayerName = rBtn.Name as string;
}
private string m_SelectLayerName;
///
/// 获取LayerWithDataListPanel中UIRadioButton的选择项,通过选择项Tag转为Layer
/// 此处的Layer只能是一个。只能按照一个图层去查询。
///
public string SelectLayerName { get => m_SelectLayerName; }
private DatasetVector m_SelectLayerDatasetVector;
///
/// 获取LayerWithDataListPanel中UIRadioButton的选择项,通过选择项Tag转为DatasetVector
///
public DatasetVector SelectLayerDatasetVector { get => m_SelectLayerDatasetVector; }
List m_SelectLayerDatasetVectors = new List();
///
/// 获取获取LayerWithDataListPanel中UICheckBox的选择项集合,通过选择项Tag转为List
///
public List SelectLayerDatasetVectors { get => m_SelectLayerDatasetVectors; }
private void InitializeComponent()
{
this.SuspendLayout();
//
// LayerWithDataListPanel
//
this.Name = "LayerWithDataListPanel";
this.Size = new System.Drawing.Size(271, 387);
this.ResumeLayout(false);
}
}
}