控制各个自定义图层显示

在载入图层的时候就将各图层名称丢入到子控件的layerList中,并调用ShowLayers()来把各个图层显示出来并加上CheckBox来控制图层的显示。
 
/// <summary>
        
/// 显示图层名称
        
/// </summary>

        public void ShowLayers()
        
{
            checkedListBoxLayerControl.Items.Clear();
            
foreach (string layer in layers)
            
{
                checkedListBoxLayerControl.Items.Add(layer);
            }

        }


        
/// <summary>
        
/// 全选按钮改变Checked状态时
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>

        private void checkAll_Click(object sender, EventArgs e)
        
{
            SetAllChecked(checkBoxAll.Checked);
        }


        
private void SetAllChecked(bool value)
        
{
            GlobalHelper.SetAllChecked(checkedListBoxLayerControl, value);
        }


        
/// <summary>
        
/// CheckedListBox中的条目改变Checked状态时
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>

        private void checkedListBoxLayerControl_ItemCheck(object sender, ItemCheckEventArgs e)
        
{
            
string layerName = checkedListBoxLayerControl.Items[e.Index].ToString();
            
if (e.NewValue == CheckState.Checked)
            
{
                
//被选择了则显示相应图层
                IMapLayer layer = mapControl.Map.Layers[layerName];
                
if (layer != null)
                    layer.Enabled 
= true;

                
//操作小图标图层
                layer = mapControl.Map.Layers["small" + layerName];
                
if (layer != null)
                    layer.Enabled 
= true;
            }

            
else
            
{
                
//否则隐藏相应图层
                IMapLayer layer = mapControl.Map.Layers[layerName];
                
if (layer != null)
                    layer.Enabled 
= false;

                
//操作小图标图层
                layer = mapControl.Map.Layers["small" + layerName];
                
if (layer != null)
                    layer.Enabled 
= false;

                checkBoxAll.Checked 
= false;
            }

        }


        
/// <summary>
        
/// 开启指定的图层,关闭其他图层
        
/// </summary>
        
/// <param name="layerNames"></param>

        public void SetLayersEnabled(ArrayList layerNames)
        
{
            
for (int i = 0; i < checkedListBoxLayerControl.Items.Count; i++)
            
{
                
string layerName = checkedListBoxLayerControl.Items[i].ToString();
                
//历史回放,隐患展现,巡检路径和巡检员定位的图层一直显示出来
                if (!layerNames.Contains(layerName) && layerName != GlobalHelper.LayerHistory && layerName != GlobalHelper.LayerTrouble
                    
&& layerName != GlobalHelper.LayerInspectman && layerName != GlobalHelper.LayerLines)
                
{
                    checkedListBoxLayerControl.SetItemChecked(i, 
false);
                }

                
else
                
{
                    checkedListBoxLayerControl.SetItemChecked(i, 
true);
                }

            }

        }


        
/// <summary>
        
/// 开启或关闭所有图层
        
/// </summary>
        
/// <param name="value"></param>

        public void SetAllLayersEnabled(bool value)
        
{
            checkBoxAll.Checked 
= value;
            SetAllChecked(value);
        }


        
/// <summary>
        
/// 开启或关闭指定图层
        
/// </summary>
        
/// <param name="layerNameTemp"></param>
        
/// <param name="bEnabled"></param>

        public void SetLayerEnabled(string layerNameTemp, bool bEnabled)
        
{
            
if (string.IsNullOrEmpty(layerNameTemp))
                
return;

            
for (int i = 0; i < checkedListBoxLayerControl.Items.Count; i++)
            
{
                
string layerName = checkedListBoxLayerControl.Items[i].ToString();
                
if (layerName.Equals(layerNameTemp))
                
{
                    checkedListBoxLayerControl.SetItemChecked(i, bEnabled);
                    
return;
                }

            }

        }

posted on 2008-10-05 10:20  TiGERTiAN  阅读(386)  评论(0编辑  收藏  举报

导航