Feature Service(二)Silverlight API在线编辑

时间:2023-01-26 18:39:14

通过FeatureService+Silverlight API实现在线编辑
   
上篇文章中已经介绍了Feature Service的一些特性和基本的发布方式,那么在这篇文章中重点介绍一下如何使用feature service去实现在线编辑。那么有两种方式访问Feature Service
     1
、通过ArcGISDeskTop的方式。
     2
、通过ArcGISServer API的方式,现在已经有两种API可以访问Feature Service,它们是Javascript. APISilverlight API,今天我重点介绍一下如何通过SilverlightAPI去访问和编辑FeatureService
如何实现:
    开发环境:
   
开发FeatureService需要ArcGISServer 10VisualStadio 2010英文版(目前中文版不支持Silverlight4Tools)、Silverlight Developer KitArcGIS Server API for Silverlight2.0_RC(正式版还没有发布)。
   
SilverlightAPI 2.0中,提供了EditWidget控件,如果对界面定制要求不高的话,可以直接使用该控件。
   
下面是实现的代码:
<UserControl x:Class=”Feature_Service.MainPage”
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
    xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″
   xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″
    mc:Ignorable=”d”
    xmlns:esri=”http://schemas.esri.com/arcgis/client/2009″>
    <Grid x:Name=”LayoutRoot” >
        <!–
地图控件–>
        <esri:Map x:Name=”MyMap”Extent=”-122.655,37.666,-122.181,37.897″>
<!–
比例尺控件–>
           <esri:Map.Template>
               <ControlTemplate>
                   <Grid Background=”{TemplateBinding Background}”>
                       <Grid x:Name=”RootElement” Width=”Auto” Height=”Auto” />
                       <Rectangle x:Name=”ZoomBox” Fill=”#55FFFFFF” Stroke=”Green”StrokeThickness=”2″ Visibility=”Collapsed” />
                       <StackPanel rientation=”Vertical” HorizontalAlignment=”Left”VerticalAlignment=”Bottom”>
                           <esri:ScaleBar x:Name=”MyScaleBar” Margin=”5″ MapUnit=”DecimalDegrees”Foreground=”Black”
                                          DisplayUnit=”Miles” Map=”{Binding ElementName=MyMap}” />
                           <TextBlock Text=”{Binding ElementName=MyMap, Path=Layers.[0].CopyrightText}”Margin=”5″ />
                       </StackPanel>
                   </Grid>
               </ControlTemplate>
           </esri:Map.Template>
           <esri:ArcGISTiledMapServiceLayer ID=”MyLayer”
               Url=”http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer”/>
            <!–
点图层–>
           <esri:FeatureLayer ID=”Point”Url=”http://localhost/ArcGIS/rest/services/FeatureService/FeatureServer/0″AutoSave=”False”  utFields=”*” Mode=”OnDemand”></esri:FeatureLayer>
            <!–
线图层–>
           <esri:FeatureLayer ID=”Line”Url=”http://localhost/ArcGIS/rest/services/FeatureService/FeatureServer/1″AutoSave=”False”  utFields=”*” Mode=”OnDemand”></esri:FeatureLayer>
            <!–
面图层–>
           <esri:FeatureLayer ID=”Polygon”Url=”http://localhost/ArcGIS/rest/services/FeatureService/FeatureServer/2″AutoSave=”False”  utFields=”*”Mode=”OnDemand”></esri:FeatureLayer>
        </esri:Map> 
        <StackPanel x:Name=”EditorToolStrip” Margin=”0,5,5,0″ >
            <BorderBackground=”#FF84AD62″ BorderThickness=”1″ CornerRadius=”5″
                      HorizontalAlignment=”Right”  VerticalAlignment=”Top”
                       Padding=”5″BorderBrush=”Black”>
               <Border.Effect>
                   <DropShadowEffect Color=”Black” Direction=”-45″ BlurRadius=”20″ pacity=”.75″/>
               </Border.Effect>
               <StackPanel rientation=”Vertical” HorizontalAlignment=”Right”Margin=”0,5,5,0″    VerticalAlignment=”Top” >
                   <esri:EditorWidget Map=”{Binding ElementName=MyMap}”
                                     Width=”300″
                                     LayerIDs=”Point,Line,Polygon”
                                     AutoSelect=”False”                                  GeometryServiceUrl=”http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer”
                                     ShowAttributesOnAdd=”True”  />
               </StackPanel>
           </Border>
        </StackPanel>
    </Grid>
</UserControl>
   
其中的点、线、面图层是在本机发布的Feature Service
   
下面是运行后的结果:

下面用ArcMap打开这两个图层,看看数据是否已经被编辑了。

在后面的文章中,我会介绍如何定制 FeatureService 的开发。