ArcGIS API for Silverlight 动态图层(ArcGISDynamicMapServiceLayer)的显示与隐藏

简介: 这里控制的是利用ArcGIS Server发布的ArcGISDynamicMapServiceLayer服务,下面的ListBox会加载所有服务图层,通过勾选可以动态控制某一个或某一些图层的显示与否。

这里控制的是利用ArcGIS Server发布的ArcGISDynamicMapServiceLayer服务,下面的ListBox会加载所有服务图层,通过勾选可以动态控制某一个或某一些图层的显示与否。主要代码如下:

<esri:ArcGISDynamicMapServiceLayer ID="MyLayer"  Url="http://192.168.0.89/arcgis/rest/services/AnHuiMap/MapServer/"  Initialized="MyLayer_Initialized" />

<!--图层控制-->
        <!--<Grid HorizontalAlignment="Right" Margin="0,260,0,0" Width="209" Height="200" VerticalAlignment="Top" >
            <Grid.RowDefinitions>
                <RowDefinition Height="0.205*"/>
                <RowDefinition Height="0.795*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="0.837*"/>
                <ColumnDefinition Width="0.163*"/>
            </Grid.ColumnDefinitions>
            <Border x:Name="bShowPicControl" BorderThickness="1"  Cursor="Hand"  Margin="1,0,0,1" Grid.Column="1" Width="33" MouseLeftButtonDown="bShowPicControl_MouseLeftButtonDown" MouseLeftButtonUp="bShowPicControl_MouseLeftButtonUp" Height="34">
                <Border.Background>
                    <ImageBrush ImageSource="Images/Layer_control.png" Stretch="None"/>
                </Border.Background>
                <ToolTipService.ToolTip>
                    <TextBlock FontSize="13.333" FontFamily="Microsoft YaHei" >图 层 控 制</TextBlock>
                </ToolTipService.ToolTip>
            </Border>
            <Grid x:Name="grid_control" Margin="0,1,0,0" Grid.RowSpan="2" Width="175" Height="199" Visibility="Collapsed">
                <Grid Height="34" Background="#FFF3F3F3" Margin="0" Width="174" VerticalAlignment="Top" d:LayoutOverrides="Height">
                    <Border BorderBrush="#FF0E529B" BorderThickness="1" CornerRadius="5" Height="34" Width="174">
                        <StackPanel Orientation="Horizontal" Width="164" Height="32">
                            <CheckBox x:Name="cb_ZM" Content="站 名" Margin="2,5,0,5" Width="54" FontSize="14.667" Cursor="Hand" FontFamily="Microsoft YaHei" VerticalAlignment="Center" HorizontalAlignment="Center" Height="18"  Checked="cb_ZM_Checked" Unchecked="cb_ZM_Unchecked"/>
                            <RadioButton x:Name="rb1" Width="54" Margin="0,5" IsChecked="True" FontSize="14.667" Content="数 据" Height="18" GroupName="gn_group" Cursor="Hand" FontFamily="Microsoft YaHei" HorizontalAlignment="Center" VerticalAlignment="Center" Click="rb_Click"/>
                            <RadioButton x:Name="rb2" Width="54" Margin="0,5" FontSize="14.667" Content="站 码" GroupName="gn_group" Cursor="Hand" FontFamily="Microsoft YaHei" HorizontalAlignment="Center" VerticalAlignment="Center" Click="rb_Click" Height="18"/>
                        </StackPanel>
                    </Border>
                </Grid>
                <Border Height="163" Margin="0,36,0,0" 
            		Width="175" d:LayoutOverrides="GridBox" BorderBrush="#FF0E529B" CornerRadius="5" BorderThickness="1" >
                    <ListBox ItemsSource="{Binding Layers.[MyLayer].Layers, ElementName=myMap}" 
            			BorderBrush="{x:Null}" FontSize="13.333" FontFamily="Microsoft YaHei" Width="173" Height="161">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <CheckBox Margin="2"
            						x:Name="MyLayer"
            						Content="{Binding Name}" 
            						IsChecked="{Binding DefaultVisibility}" 
            						Tag="{Binding ID}"
            						ClickMode="Press" 
            						Click="CheckBox_Click" />
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Border>
            </Grid>
        </Grid>-->

#region 图层控制显示与隐藏

        private void MyLayer_Initialized(object sender, EventArgs e)
        {
            ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicServiceLayer =
                sender as ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer;
            if (dynamicServiceLayer.VisibleLayers == null)
                dynamicServiceLayer.VisibleLayers = GetDefaultVisibleLayers(dynamicServiceLayer);
        }

        private int[] GetDefaultVisibleLayers(ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicService)
        {
            List<int> visibleLayerIDList = new List<int>();

            ESRI.ArcGIS.Client.LayerInfo[] layerInfoArray = dynamicService.Layers;

            for (int index = 0; index < layerInfoArray.Length; index++)
            {
                if (layerInfoArray[index].DefaultVisibility)
                    visibleLayerIDList.Add(index);
            }
            return visibleLayerIDList.ToArray();
        }

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox tickedCheckBox = sender as CheckBox;

            string serviceName = tickedCheckBox.Name;
            bool visible = (bool)tickedCheckBox.IsChecked;

            int layerIndex = (int)tickedCheckBox.Tag;

            ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer dynamicServiceLayer = myMap.Layers[serviceName] as
                ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer;

            List<int> visibleLayerList =
                dynamicServiceLayer.VisibleLayers != null
                ? dynamicServiceLayer.VisibleLayers.ToList() : new List<int>();

            if (visible)
            {
                if (!visibleLayerList.Contains(layerIndex))
                    visibleLayerList.Add(layerIndex);
            }
            else
            {
                if (visibleLayerList.Contains(layerIndex))
                    visibleLayerList.Remove(layerIndex);
            }

            dynamicServiceLayer.VisibleLayers = visibleLayerList.ToArray();
        }

        #endregion


相关文章
|
存储
ArcGIS:模型构建器内变量的数据类型中栅格图层和栅格数据集的区别
ArcGIS:模型构建器内变量的数据类型中栅格图层和栅格数据集的区别
109 0
|
存储 C语言
ArcGIS:Excel/Txt 文件生成点图层、属性表编辑的基本方法、属性表之间的连接(合并)和关联的操作、属性表的字段计算器的使用
ArcGIS:Excel/Txt 文件生成点图层、属性表编辑的基本方法、属性表之间的连接(合并)和关联的操作、属性表的字段计算器的使用
314 0
|
6月前
|
定位技术
ArcGIS中ArcMap栅格图层0值设置为NoData值的简便方法
ArcGIS中ArcMap栅格图层0值设置为NoData值的简便方法
151 1
|
6月前
|
定位技术 Windows
ArcGIS中ArcMap图层属性表的中文字段乱码的解决方法
ArcGIS中ArcMap图层属性表的中文字段乱码的解决方法
657 1
|
6月前
ArcGIS中ArcMap为不含坐标系的图层添加地理坐标系或投影坐标系
ArcGIS中ArcMap为不含坐标系的图层添加地理坐标系或投影坐标系
148 1
|
6月前
|
数据库
ArcGIS中ArcMap新建矢量点线面要素图层并手动划定要素图层范围区域
ArcGIS中ArcMap新建矢量点线面要素图层并手动划定要素图层范围区域
156 1
|
6月前
ArcGIS修改图层标签标注(Label)对应字段与内容的方法
ArcGIS修改图层标签标注(Label)对应字段与内容的方法
215 1
|
6月前
|
定位技术
ArcGIS批量计算图层中矢量要素面积——ArcMap
ArcGIS批量计算图层中矢量要素面积——ArcMap
172 1
|
6月前
|
定位技术
ArcGIS矢量图层投影与地理坐标系转为投影坐标系——ArcMap
ArcGIS矢量图层投影与地理坐标系转为投影坐标系——ArcMap
139 1
|
人工智能 数据可视化 API
ArcGIS API for Python
ArcGIS API for Python
66 0