ArcGIS API for Silverlight 3.0更新(1)ArcGISDynamicMapServiceLayer

本文介绍如何通过ArcGISDynamicMapServiceLayer改变渲染效果、调整图层顺序及添加图层。利用C#代码和XAML实现图层定义、绘制选项及动态图层信息的设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果图

此示例演示了如何改变的渲染,改变图层的顺序,添加图层在飞行中的ArcGISDynamicMapServiceLayer。要使用示例,点击左上角的按钮的应用程序。
在代码背后,ArcGISDynamicMapServiceLayer.LayerDrawingOptions和ArcGISDynamicMapServiceLayer.DynamicLayerInfos性能的基础上被点击的按钮以应用更改。
点击值的范围渲染器渲染按钮或独特的价值生成一个适当类型的渲染器,创建一个新的LayerDrawingOptions对象,并设置其Renderer属性,生成的渲染,然后使用的LayerDrawingOptions的财产,申请新的渲染。
单击“更改图层顺序”按钮,清除其设置为null使用的DynamicLayerInfoCollection.RemoveAt和DynamicLayerInfoCollection.Add移动一个层层的LayerDrawingOptions的。
单击“添加图层”按钮得到一个层使用的TableDataSource的和把它添加到地图使用DynamicLayerInfos的。

源代码

前端XAML
 1 <UserControl x:Class="ArcGISSilverlightSDK.DynamicLayer"
 2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 5     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 6     xmlns:esri="http://schemas.esri.com/arcgis/client/2009">
 7 
 8     <Grid x:Name="LayoutRoot" Background="White">
 9         <esri:Map x:Name="MyMap">
10             <esri:Map.Extent>
11                 <esri:Envelope XMin="-3548912" YMin="-1847469" XMax="2472012" YMax="1742990">
12                     <esri:Envelope.SpatialReference>
13                         <esri:SpatialReference WKID="102009"/>
14                     </esri:Envelope.SpatialReference>
15                 </esri:Envelope>
16             </esri:Map.Extent>
17             <esri:ArcGISDynamicMapServiceLayer ID="USA"                
18                 Url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer" />
19         </esri:Map>
20 
21         <StackPanel Orientation="Vertical">
22             <Button Content="Range Value Renderer" Click="ApplyRangeValueClick" Width="140" Height="30" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5"/>
23             <Button Content="Unique Value Renderer" Click="ApplyUniqueValueClick" Width="140" Height="30" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5"/>
24             <Button Content="Change Layer Order" Click="ChangeLayerOrderClick" Width="140" Height="30" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5"/>
25             <Button Content="Add Layer" Click="AddLayerClick" Width="140" Height="30" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5"/>
26         </StackPanel>
27     </Grid>
28 </UserControl>
后台代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Net;
  5 using System.Windows;

  6 using System.Windows.Controls;
  7 using System.Windows.Documents;
  8 using System.Windows.Input;
  9 using System.Windows.Media;
 10 using System.Windows.Media.Animation;
 11 using System.Windows.Shapes;
 12 using ESRI.ArcGIS.Client;
 13 using ESRI.ArcGIS.Client.Symbols;
 14 using ESRI.ArcGIS.Client.Geometry;
 15 
 16 namespace ArcGISSilverlightSDK
 17 {
 18     public partial class DynamicLayer : UserControl
 19     {
 20         public DynamicLayer()
 21         {
 22             InitializeComponent();          
 23         }
 24 
 25         private void ApplyRangeValueClick(object sender, RoutedEventArgs e)
 26         {
 27             ClassBreaksRenderer newClassBreaksRenderer = new ClassBreaksRenderer();
 28             newClassBreaksRenderer.Field = "POP00_SQMI";
 29 
 30             newClassBreaksRenderer.Classes.Add(new ClassBreakInfo()
 31             {
 32                 MinimumValue = 0,
 33                 MaximumValue = 12,
 34                 Symbol = new SimpleFillSymbol()
 35                 {
 36                     Fill = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0))
 37                 }
 38             });
 39 
 40             newClassBreaksRenderer.Classes.Add(new ClassBreakInfo()
 41             {
 42                 MaximumValue = 31.3,
 43                 Symbol = new SimpleFillSymbol()
 44                 {
 45                     Fill = new SolidColorBrush(Color.FromArgb(255, 100, 255, 100))
 46                 }
 47             });
 48 
 49             newClassBreaksRenderer.Classes.Add(new ClassBreakInfo()
 50             {
 51                 MaximumValue = 59.7,
 52                 Symbol = new SimpleFillSymbol()
 53                 {
 54                     Fill = new SolidColorBrush(Color.FromArgb(255, 0, 255, 200))
 55                 }
 56             });
 57 
 58             newClassBreaksRenderer.Classes.Add(new ClassBreakInfo()
 59             {
 60                 MaximumValue = 146.2,
 61                 Symbol = new SimpleFillSymbol()
 62                 {
 63                     Fill = new SolidColorBrush(Color.FromArgb(255, 0, 255, 255))
 64                 }
 65             });
 66 
 67             newClassBreaksRenderer.Classes.Add(new ClassBreakInfo()
 68             {
 69                 MaximumValue = 57173,
 70                 Symbol = new SimpleFillSymbol()
 71                 {
 72                     Fill = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255))
 73                 }
 74             });
 75 
 76             LayerDrawingOptions layerDrawOptions = new LayerDrawingOptions();
 77             layerDrawOptions.LayerID = 3;
 78             layerDrawOptions.Renderer = newClassBreaksRenderer;
 79 
 80             (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).LayerDrawingOptions =
 81                 new LayerDrawingOptionsCollection() { layerDrawOptions };
 82             (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).VisibleLayers = new int[] { 3 };
 83             // Changing VisibleLayers will refresh the layer, otherwise an explicit call to Refresh is needed.
 84             //(MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).Refresh();
 85         }
 86 
 87         private void ApplyUniqueValueClick(object sender, RoutedEventArgs e)
 88         {
 89             UniqueValueRenderer newUniqueValueRenderer = new UniqueValueRenderer()
 90             {
 91                 DefaultSymbol = new SimpleFillSymbol()
 92                 {
 93                     Fill = new SolidColorBrush(Colors.Gray)
 94                 },
 95                 Field = "SUB_REGION"
 96             };
 97 
 98             newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
 99             {
100                 Value = "Pacific",
101                 Symbol = new SimpleFillSymbol()
102                 {
103                     Fill = new SolidColorBrush(Colors.Purple),
104                     BorderBrush = new SolidColorBrush(Colors.Transparent)
105                 }
106             });
107 
108             newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
109             {
110                 Value = "W N Cen",
111                 Symbol = new SimpleFillSymbol()
112                 {
113                     Fill = new SolidColorBrush(Colors.Green),
114                     BorderBrush = new SolidColorBrush(Colors.Transparent)
115                 }
116             });
117 
118             newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
119             {
120                 Value = "W S Cen",
121                 Symbol = new SimpleFillSymbol()
122                 {
123                     Fill = new SolidColorBrush(Colors.Cyan),
124                     BorderBrush = new SolidColorBrush(Colors.Transparent)
125                 }
126             });
127 
128             newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
129             {
130                 Value = "E N Cen",
131                 Symbol = new SimpleFillSymbol()
132                 {
133                     Fill = new SolidColorBrush(Colors.Yellow),
134                     BorderBrush = new SolidColorBrush(Colors.Transparent)
135                 }
136             });
137 
138             newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
139             {
140                 Value = "Mtn",
141                 Symbol = new SimpleFillSymbol()
142                 {
143                     Fill = new SolidColorBrush(Colors.Blue),
144                     BorderBrush = new SolidColorBrush(Colors.Transparent)
145                 }
146             });
147 
148             newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
149             {
150                 Value = "N Eng",
151                 Symbol = new SimpleFillSymbol()
152                 {
153                     Fill = new SolidColorBrush(Colors.Red),
154                     BorderBrush = new SolidColorBrush(Colors.Transparent)
155                 }
156             });
157 
158             newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
159             {
160                 Value = "E S Cen",
161                 Symbol = new SimpleFillSymbol()
162                 {
163                     Fill = new SolidColorBrush(Colors.Brown),
164                     BorderBrush = new SolidColorBrush(Colors.Transparent)
165                 }
166             });
167 
168             newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
169             {
170                 Value = "Mid Atl",
171                 Symbol = new SimpleFillSymbol()
172                 {
173                     Fill = new SolidColorBrush(Colors.Magenta),
174                     BorderBrush = new SolidColorBrush(Colors.Transparent)
175                 }
176             });
177 
178             newUniqueValueRenderer.Infos.Add(new UniqueValueInfo()
179             {
180                 Value = "S Atl",
181                 Symbol = new SimpleFillSymbol()
182                 {
183                     Fill = new SolidColorBrush(Colors.Orange),
184                     BorderBrush = new SolidColorBrush(Colors.Transparent)
185                 }
186             });
187 
188             LayerDrawingOptions layerDrawOptions = new LayerDrawingOptions();
189             layerDrawOptions.LayerID = 2;
190             layerDrawOptions.Renderer = newUniqueValueRenderer;
191 
192             (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).LayerDrawingOptions =
193                 new LayerDrawingOptionsCollection() { layerDrawOptions };
194             (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).VisibleLayers = new int[] { 2 };
195             // Changing VisibleLayers will refresh the layer, otherwise an explicit call to Refresh is needed.
196             //(MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).Refresh();
197 
198         }
199 
200         private void ChangeLayerOrderClick(object sender, RoutedEventArgs e)
201         {
202             (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).LayerDrawingOptions = null;
203 
204             DynamicLayerInfoCollection myDynamicLayerInfos = (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).DynamicLayerInfos;
205             if (myDynamicLayerInfos == null)
206                 myDynamicLayerInfos = (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).CreateDynamicLayerInfosFromLayerInfos();
207 
208             var aDynamicLayerInfo = myDynamicLayerInfos[0];
209             myDynamicLayerInfos.RemoveAt(0);
210             myDynamicLayerInfos.Add(aDynamicLayerInfo);
211 
212             (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).DynamicLayerInfos = myDynamicLayerInfos;
213             (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).VisibleLayers = null;
214             // Changing VisibleLayers will refresh the layer, otherwise an explicit call to Refresh is needed.
215             //(MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).Refresh();
216         }
217 
218         private void AddLayerClick(object sender, RoutedEventArgs e)
219         {
220             (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).LayerDrawingOptions = null;
221 
222             DynamicLayerInfoCollection myDynamicLayerInfos = (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).DynamicLayerInfos;
223             if (myDynamicLayerInfos == null)
224                 myDynamicLayerInfos = (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).CreateDynamicLayerInfosFromLayerInfos();
225 
226             DynamicLayerInfo dli = new DynamicLayerInfo()
227             {
228                 ID = 4,
229                 Source = new LayerDataSource()
230                 {
231                     DataSource = new TableDataSource()
232                     {
233                         WorkspaceID = "MyDatabaseWorkspaceIDSSR2",
234                         DataSourceName = "ss6.gdb.Lakes"
235                     }
236                 }
237             };
238 
239             LayerDrawingOptions layerDrawOptions = new LayerDrawingOptions();
240             layerDrawOptions.LayerID = 4;
241             layerDrawOptions.Renderer = new SimpleRenderer()
242             {
243                 Symbol = new SimpleFillSymbol()
244                 {
245                     Fill = new SolidColorBrush(Color.FromArgb((int)255, (int)0, (int)0, (int)255))
246                 }
247             };
248 
249             (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).LayerDrawingOptions =
250                 new LayerDrawingOptionsCollection() { layerDrawOptions };
251 
252             myDynamicLayerInfos.Insert(0, dli);
253             (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).DynamicLayerInfos = myDynamicLayerInfos;
254             (MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).VisibleLayers = new int[] { 3,4 };
255             // Changing VisibleLayers will refresh the layer, otherwise an explicit call to Refresh is needed.
256             //(MyMap.Layers["USA"] as ArcGISDynamicMapServiceLayer).Refresh();
257         }
258     }
259 }

在线DEMO

以上主要是在后台C#托管代码中进行处理

下面看一下在XAML前也可以进行处理

效果图

此示例演示使用XAML指定一个ArcGISDynamicMapServiceLayer的的的LayerDefinitions,LayerDrawingOptions,并DynamicLayerInfos的。 LayerDefinition设置的USCities层,只显示大写。 LayerDrawingOptions设置0层和4,使用SimpleRenderer和第2层使用ClassBreaksRenderer。 DynamicLayerInfos财产是用来添加这些层上飞设置Source属性LayerMapSources,和TableDataSource。这些属性将应用于地图加载

源代码:

前端代码
  1 <UserControl x:Class="ArcGISSilverlightSDK.DynamicLayerXAML"
  2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6     mc:Ignorable="d" xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
  7     d:DesignHeight="300" d:DesignWidth="400">
  8     
  9     <Grid x:Name="LayoutRoot" Background="White">
 10         <esri:Map x:Name="MyMap">
 11             <esri:Map.Extent>
 12                 <esri:Envelope XMin="-3170138" YMin="-1823795" XMax="2850785" YMax="1766663">
 13                     <esri:Envelope.SpatialReference>
 14                         <esri:SpatialReference WKID="102009"/>
 15                     </esri:Envelope.SpatialReference>
 16                 </esri:Envelope>
 17             </esri:Map.Extent>
 18             <esri:ArcGISDynamicMapServiceLayer ID="USA"                
 19                 Url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer" 
 20                 VisibleLayers="0,2,4">
 21                 <esri:ArcGISDynamicMapServiceLayer.LayerDefinitions>
 22                     <esri:LayerDefinition LayerID="0" Definition="CAPITAL = 'Y'" />                       
 23                 </esri:ArcGISDynamicMapServiceLayer.LayerDefinitions>
 24                 <esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions>
 25                     <esri:LayerDrawingOptionsCollection>
 26                         <esri:LayerDrawingOptions LayerID="0" ShowLabels="True">
 27                             <esri:LayerDrawingOptions.Renderer>
 28                                 <esri:SimpleRenderer>
 29                                         <esri:SimpleMarkerSymbol Color="Red" Size="10" Style="Diamond" />
 30                                 </esri:SimpleRenderer>
 31                             </esri:LayerDrawingOptions.Renderer>
 32                         </esri:LayerDrawingOptions>
 33                         <esri:LayerDrawingOptions LayerID="2">
 34                             <esri:LayerDrawingOptions.Renderer>
 35                                 <esri:ClassBreaksRenderer Field="POP2000">
 36                                     <esri:ClassBreakInfo MaximumValue="1000000" MinimumValue="0">
 37                                         <esri:SimpleFillSymbol 
 38                                             BorderThickness="1" 
 39                                             Fill="#74E01B" 
 40                                             BorderBrush="Transparent" />
 41                                     </esri:ClassBreakInfo>
 42                                     <esri:ClassBreakInfo MaximumValue="2000000">
 43                                         <esri:SimpleFillSymbol 
 44                                             BorderThickness="1" 
 45                                             Fill="#1BE025" 
 46                                             BorderBrush="Transparent" />
 47                                     </esri:ClassBreakInfo>
 48                                     <esri:ClassBreakInfo MaximumValue="5000000">
 49                                         <esri:SimpleFillSymbol 
 50                                             BorderThickness="1" 
 51                                             Fill="#1BE087" 
 52                                             BorderBrush="Transparent" />
 53                                     </esri:ClassBreakInfo>
 54                                     <esri:ClassBreakInfo MaximumValue="10000000">
 55                                         <esri:SimpleFillSymbol 
 56                                             BorderThickness="1" 
 57                                             Fill="#D6E01B" 
 58                                             BorderBrush="Transparent" />
 59                                     </esri:ClassBreakInfo>
 60                                     <esri:ClassBreakInfo MaximumValue="40000000">
 61                                         <esri:SimpleFillSymbol 
 62                                             BorderThickness="1" 
 63                                             Fill="#E0871B" 
 64                                             BorderBrush="Transparent" />
 65                                     </esri:ClassBreakInfo>
 66                                 </esri:ClassBreaksRenderer>
 67                             </esri:LayerDrawingOptions.Renderer>
 68                         </esri:LayerDrawingOptions>
 69                         <esri:LayerDrawingOptions LayerID="4">
 70                             <esri:LayerDrawingOptions.Renderer>
 71                                 <esri:SimpleRenderer>
 72                                     <esri:SimpleFillSymbol Fill="Blue" BorderBrush="Black" />
 73                                 </esri:SimpleRenderer>
 74                             </esri:LayerDrawingOptions.Renderer>
 75                         </esri:LayerDrawingOptions>
 76                     </esri:LayerDrawingOptionsCollection>
 77                 </esri:ArcGISDynamicMapServiceLayer.LayerDrawingOptions>
 78                 <esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos>
 79                     <esri:DynamicLayerInfoCollection>
 80                         <esri:DynamicLayerInfo ID="0">
 81                             <esri:DynamicLayerInfo.Source>
 82                                 <esri:LayerMapSource MapLayerID="0" />
 83                             </esri:DynamicLayerInfo.Source>
 84                         </esri:DynamicLayerInfo>
 85                         <esri:DynamicLayerInfo ID="4">
 86                             <esri:DynamicLayerInfo.Source>
 87                                 <esri:LayerDataSource>
 88                                     <esri:LayerDataSource.DataSource>
 89                                         <esri:TableDataSource 
 90                                             WorkspaceID="MyDatabaseWorkspaceIDSSR2" 
 91                                             DataSourceName="ss6.gdb.Lakes" />
 92                                     </esri:LayerDataSource.DataSource>
 93                                 </esri:LayerDataSource>
 94                             </esri:DynamicLayerInfo.Source>
 95                         </esri:DynamicLayerInfo>
 96                         <esri:DynamicLayerInfo ID="2">
 97                             <esri:DynamicLayerInfo.Source>
 98                                 <esri:LayerMapSource MapLayerID="2" />
 99                             </esri:DynamicLayerInfo.Source>
100                         </esri:DynamicLayerInfo>
101                     </esri:DynamicLayerInfoCollection>
102                 </esri:ArcGISDynamicMapServiceLayer.DynamicLayerInfos>
103             </esri:ArcGISDynamicMapServiceLayer>
104         </esri:Map>
105     </Grid>
106 </UserControl>
后台代码
 1 using System.Windows.Controls;
 2 
 3 namespace ArcGISSilverlightSDK
 4 {
 5     public partial class DynamicLayerXAML : UserControl
 6     {
 7         public DynamicLayerXAML()
 8         {
 9             InitializeComponent();
10         }
11     }
12 }

在线DEMO

 

 

 

 

 

转载于:https://www.cnblogs.com/jstangwh/archive/2012/10/18/2730266.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值