ArcGIS API for Silverlight 動態圖層(ArcGISDynamicMapServiceLayer)的顯示與隱藏
這裡控制的是利用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
相關文章
- 在 Laravel 中動態 隱藏 / 顯示 API 欄位LaravelAPI
- jqgrid動態顯示,隱藏指定列
- jQuery動畫的顯示與隱藏效果jQuery動畫
- jQuery動畫的顯示與隱藏效果!jQuery動畫
- vue 滑鼠移入顯示圖示 ,滑鼠移出隱藏圖示Vue
- mac顯示隱藏檔案,取消顯示隱藏檔案Mac
- 動態控制C4C UI元素的顯示和隱藏UI
- JavaScript 設定div顯示與隱藏JavaScript
- jQuery 實現顯示與隱藏效果jQuery
- 如何隱藏工作列的圖示win10_win10怎麼隱藏狀態列圖示Win10
- win10 如何顯示隱藏圖示_win10系統右下角的圖示怎麼隱藏Win10
- win10圖示隱藏了怎麼弄出來_win10顯示隱藏的圖示設定方法Win10
- win10隱藏桌面圖示怎麼顯示 win10隱藏桌面圖示如何恢復Win10
- iOS 隱藏&顯示tabBariOStabBar
- Mac顯示和隱藏“隱藏檔案”命令Mac
- vue.js顯示與隱藏(v-if)Vue.js
- element-plus el-table 動態設定列顯示隱藏
- FloatingActionButton在RecycleView中滑動隱藏顯示View
- 區塊的顯示和隱藏
- excel隱藏的部分如何顯示出來 excel裡面怎麼顯示隱藏部分Excel
- OSX中隱藏和顯示[隱藏檔案]的命令列命令列
- Android 顯示、隱藏狀態列和導航欄Android
- jQuery 效果 – 隱藏和顯示jQuery
- Mac顯示/不顯示隱藏檔案教程!Mac
- javascript隱藏和顯示div的方法JavaScript
- CSS 小結筆記之元素的隱藏與顯示CSS筆記
- Three.js控制物體顯示與隱藏的方法JS
- JavaScript動畫方式控制div元素的隱藏和顯示JavaScript動畫
- steam隱藏的遊戲怎麼顯示出來 steam隱藏顯示遊戲方法介紹遊戲
- fltk-rs 隱藏標題欄但顯示工作列圖示
- MACOS 如何顯示隱藏檔案Mac
- 【macOS】顯示/隱藏 指定檔案Mac
- win10 如何顯示隱藏資料夾_win10 如何顯示隱藏的資料夾Win10
- 【CSS】CSS 世界 — 元素的顯示與隱藏學習總結CSS
- 元素的隱藏和顯示(display ,visibility ,overflow)
- DevExpress隱藏列表中顯示的加號+devExpress
- 短視訊程式開發,動態實現密碼、核取方塊等顯示與隱藏密碼
- win10怎麼顯示隱藏資料夾 win10顯示隱藏資料夾的方法Win10
- win10怎麼隱藏桌面圖示_win10如何隱藏桌面圖示Win10