Select to view content in your preferred language

ESRI.ArcGIS.Client.Editor Class And the ESRI Feature Layer

2649
8
03-03-2011 03:03 AM
jonataspovoas
Regular Contributor
Hi,

I'm developing an Application to Online Map Editing, so i looked at the sample on this link : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsAutoSave.

I'd like to know a bit more about the FeatureLayer and the Editor Classes, and where can i find their class diagram? Is there Any more Samples of their usage?
0 Kudos
8 Replies
jonataspovoas
Regular Contributor
Hi,

After reading this documentations i started this test application.

<UserControl x:Class="EditorDeMapas.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:esri="http://schemas.esri.com/arcgis/client/2009"
    xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client"    
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
 mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600" 
 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:userControls="clr-namespace:ESRI.ArcGIS.SilverlightMapApp"
    xmlns:actions="clr-namespace:ESRI.ArcGIS.SilverlightMapApp.Actions">
    <UserControl.Resources>
        <esriSymbols:SimpleFillSymbol x:Name="Default" Fill="#33FF0000" BorderBrush="Red" BorderThickness="2" />
        <esriSymbols:SimpleFillSymbol  x:Name="area" ControlTemplate="{StaticResource EstiloDefaultFillSymbol}"/>
        <esriSymbols:SimpleLineSymbol x:Name="linha" ControlTemplate="{StaticResource EstiloLineSymbol}"/>
        <esriSymbols:SimpleMarkerSymbol x:Name="ponto" ControlTemplate="{StaticResource EstiloMarkerSymbol}"/>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="{StaticResource BaseColor}">
        <Border>
            <esri:Map x:Name="mapa" Extent="-13054165,3850112,-13027133,3863559" esri:Editor.SnapDistance="20" esri:Editor.SnapKey="S">
                <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" 
                                     Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
                <esri:FeatureLayer ID="featureParaPontos"  
                               Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer/0"                  
                               AutoSave="False" 
                               Mode="OnDemand" 
                               ValidateEdits="True" 
                               DisableClientCaching="True" />
                <esri:FeatureLayer ID="featureParaLinha"  
                               Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer/1"                  
                               AutoSave="False" 
                               Mode="OnDemand" 
                               ValidateEdits="True" 
                               DisableClientCaching="True" />
                <esri:FeatureLayer ID="featureParaArea"  
                               Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer/2"                  
                               AutoSave="False" 
                               Mode="OnDemand" 
                               ValidateEdits="True" 
                               DisableClientCaching="True" />
            </esri:Map>
        </Border>
        <Border VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,5,5,0">
            <Border.Resources>
                <esri:Editor x:Key="editorGeral" Map="{Binding ElementName=mapa}" LayerIDs="featureParaPontos,featureParaLinha,featureParaArea"/>
                <esri:Editor x:Key="editorPonto" Map="{Binding ElementName=mapa}" LayerIDs="featureParaPontos"/>
                <esri:Editor x:Key="editorLinha" Map="{Binding ElementName=mapa}" LayerIDs="featureParaLinha"/>
                <esri:Editor x:Key="editorArea" Map="{Binding ElementName=mapa}" LayerIDs="featureParaArea"/>
            </Border.Resources>
            <StackPanel DataContext="{StaticResource editorGeral}">
                <Button Content="Select" Command="{Binding Select}" CommandParameter="New" />
                <Button Content="Add Selection" Command="{Binding Select}" CommandParameter="Add" />
                <Button Content="Unselect" Command="{Binding Select}" CommandParameter="Remove" />
                <Button Content="Clear Selection" Command="{Binding ClearSelection}" />
                <Button Content="Add Default" Command="{Binding Add}" />
                <StackPanel DataContext="{StaticResource editorPonto}">
                    <Button Content="Add Point" Command="{Binding Add}" CommandParameter="ponto"/>
                </StackPanel>
                <StackPanel DataContext="{StaticResource editorLinha}">
                <Button Content="Add Line" Command="{Binding Add}" CommandParameter="{StaticResource linha}"/>
                </StackPanel>
                <StackPanel DataContext="{StaticResource editorArea}">
                    <Button Content="Add Area" Command="{Binding Add}" CommandParameter="{StaticResource area}"/>
                </StackPanel>
                <Button Content="Save" Command="{Binding Save}" />
                <Button Content="Delete Selected" Command="{Binding DeleteSelected}" />
                <!--<CheckBox IsChecked="{Binding Path=Freehand, Mode=TwoWay}" Content="Freehand Draw" VerticalAlignment="Center" />-->
            </StackPanel>
        </Border>
    </Grid>
</UserControl>


Now i have a question: How can I use the symbols i creted ("Deafult","area","linha" and "ponto")?
0 Kudos
JenniferNery
Esri Regular Contributor
If you are looking into using these symbols for Editor.Add on GraphicsLayer. This is related thread: http://forums.arcgis.com/threads/25176-Versatile-symbol-selector-for-drawing

As described in this document: http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Editor~Add...

You need one editor per layer for Add to be enabled. CommandParameter can either take a symbol for GraphicsLayer or feature type for FeatureLayer.
0 Kudos
jonataspovoas
Regular Contributor
I managed to make the editor, now update to the code below, but somehow my feature service isn't comunicating well with my application.

<UserControl x:Class="EditorDeMapas.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:esri="http://schemas.esri.com/arcgis/client/2009"
    xmlns:esriSymbols="clr-namespace:ESRI.ArcGIS.Client.Symbols;assembly=ESRI.ArcGIS.Client"    
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
 mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600" 
 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:userControls="clr-namespace:ESRI.ArcGIS.SilverlightMapApp"
    xmlns:actions="clr-namespace:ESRI.ArcGIS.SilverlightMapApp.Actions">
    <UserControl.Resources>
        <esriSymbols:SimpleFillSymbol x:Name="Default" Fill="#33FF0000" BorderBrush="Red" BorderThickness="2" />
        <esriSymbols:SimpleFillSymbol  x:Name="area" ControlTemplate="{StaticResource EstiloDefaultFillSymbol}"/>
        <esriSymbols:SimpleLineSymbol x:Name="linha" ControlTemplate="{StaticResource EstiloLineSymbol}"/>
        <esriSymbols:SimpleMarkerSymbol x:Name="ponto" ControlTemplate="{StaticResource EstiloMarkerSymbol}"/>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="{StaticResource BaseColor}">
        <Border>
            <esri:Map x:Name="mapa" Background="Aqua" esri:Editor.SnapDistance="20" esri:Editor.SnapKey="S">

               <esri:ArcGISDynamicMapServiceLayer ID="Mapa Base" 
                                                   ImageFormat="JPG"
                                                   Url="http://192.168.5.4/ArcGIS/rest/services/MDSalvador/1MapaBase14-01-2011/MapServer"/>

                <esri:ArcGISDynamicMapServiceLayer ID="Sistema de Transporte" 
                                                   ImageFormat="PNG32"
                                                   Url="http://192.168.5.4/ArcGIS/rest/services/MDSalvador/5MapaTopo14-01-2011/MapServer"/>

                <esri:ArcGISDynamicMapServiceLayer ID="Bairros" 
                                                   ImageFormat="PNG32"
                                                   Url="http://192.168.5.4/ArcGIS/rest/services/MDSalvador/3SistemadeTransporte14-01-2011/MapServer"/>

                <esri:ArcGISDynamicMapServiceLayer ID="Mapa Topo" 
                                                   ImageFormat="PNG32"
                                                   Url="http://192.168.5.4/ArcGIS/rest/services/MDSalvador/4Bairros03-11-2010-1/MapServer"/>

                <esri:ArcGISDynamicMapServiceLayer ID="Pontos de Referencia" 
                                                   ImageFormat="PNG32"
                                                   Url="http://192.168.5.4/ArcGIS/rest/services/MDSalvador/6PontosDeReferencia03-11-2010-1/MapServer"/>

                <esri:FeatureLayer ID="featureParaArea"  
                               Url="http://192.168.5.104/ArcGIS/rest/services/Projeto_SL/FeatureServer/2"                  
                               AutoSave="False" 
                               Mode="OnDemand" 
                               ValidateEdits="True"
                               Visible="True"
                               DisableClientCaching="True" />
                <esri:FeatureLayer ID="featureParaLinha"  
                               Url="http://192.168.5.104/ArcGIS/rest/services/Projeto_SL/FeatureServer/1"                  
                               AutoSave="False" 
                               Mode="Snapshot" 
                               ValidateEdits="True" 
                               Visible="True"
                               DisableClientCaching="False" />
                <esri:FeatureLayer ID="featureParaPontos"  
                               Url="http://192.168.5.104/ArcGIS/rest/services/Projeto_SL/FeatureServer/0"                  
                               AutoSave="False" 
                               Mode="Snapshot" 
                               ValidateEdits="True" 
                               Visible="True"
                               DisableClientCaching="False" />
            </esri:Map>
        </Border>
        <esri:MapProgressBar Map="{Binding ElementName=mapa}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="200" Height="12" Margin="0" BorderBrush="#FF18428C" Foreground="#FF18428C" Background="#FF26A1E2" d:LayoutOverrides="Height" Grid.Row="1"/>
        <Border VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,5,5,0">
            <Border.Resources>
                <esri:Editor x:Key="editorGeral" Map="{Binding ElementName=mapa}" LayerIDs="featureParaPontos,featureParaLinha,featureParaArea"/>
                <esri:Editor x:Key="editorPonto" Map="{Binding ElementName=mapa}" LayerIDs="featureParaPontos"/>
                <esri:Editor x:Key="editorLinha" Map="{Binding ElementName=mapa}" LayerIDs="featureParaLinha"/>
                <esri:Editor x:Key="editorArea" Map="{Binding ElementName=mapa}" LayerIDs="featureParaArea"/>
            </Border.Resources>
            <StackPanel DataContext="{StaticResource editorGeral}">
                <Button Content="Select" Command="{Binding Select}" CommandParameter="New" />
                <Button Content="Add Selection" Command="{Binding Select}" CommandParameter="Add" />
                <Button Content="Unselect" Command="{Binding Select}" CommandParameter="Remove" />
                <Button Content="Clear Selection" Command="{Binding ClearSelection}" />
                <Button Content="Add Default" Command="{Binding Add}" />
                <StackPanel DataContext="{StaticResource editorPonto}">
                    <Button Content="Add Point" Command="{Binding Add}"/>
                </StackPanel>
                <StackPanel DataContext="{StaticResource editorLinha}">
                    <Button Content="Add Line" Command="{Binding Add}"/>
                </StackPanel>
                <StackPanel DataContext="{StaticResource editorArea}">
                    <Button Content="Add Area" Command="{Binding Add}"/>
                </StackPanel>
                <Button Content="Save" Command="{Binding Save}" />
                <Button Content="Delete Selected" Command="{Binding DeleteSelected}" />
            </StackPanel>
        </Border>
    </Grid>
</UserControl>


When i use the application to Edit and save it, the changes (except fill symbols with crossed edges) are saved, and i can see it at the ArcGIS Server image and at the ArcCatalog, but other then area fill symbols, the other changes i saved don't show on the application if i refresh it.

What am i doing wrong?
0 Kudos
JenniferNery
Esri Regular Contributor
I don't see where you set the CommandParameter for the Add button. If the Editor is working against a FeatureLayer, the CommandParameter must match a feature type in your service.
0 Kudos
ThomasSchultz
Deactivated User
Hi Jennifer,

Is there a way to set the CommandParameter for my Add button to an extent or area.  Right now my Add button allows the user to draw a polygon on the map, which is the geomtery type of the FeatureLayer I am editing against.  This works okay, but I'd like to only allow the users to draw a rectangle, or extent on the map.   I couldn't find in the documentation what all of the available feature types were.
0 Kudos
JenniferNery
Esri Regular Contributor
Here's some documentation:
Editor.Add CommandParamater when working against FeatureLayer is expected to be a FeatureTypeId
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Editor~Add...
You can get access to your layer's FeatureType through FeatureLayer.LayerInfo.FeatureTypes, this value allows the layer renderer to determine what symbol to use for the given feature type.
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureSer...

Adding a shape (like rectangle) is not supported in Editor.Add, you would have to use Draw class with DrawMode.Rectangle. In Draw.DrawComplete, convert envelope to a polygon geometry and add type id attribute so your layer.Renderer can pick a symbol.
private void draw_DrawComplete(object sender, DrawEventArgs e)
{ 
 if (layer.LayerInfo.GeometryType == GeometryType.Polygon)
 {
  graphic.Attributes[layer.LayerInfo.TypeIdField] = typeId;
  Graphic graphic = new Graphic();
  Polygon polygon = e.Geometry is Polygon ? result as Polygon : new Polygon();
  if (e.Geometry is Envelope)
   polygon.Rings.Add(GetPointCollectionFromEnvelope(result as Envelope));
  graphic.Geometry = polygon;
  layer.Graphics.Add(graphic);
 }
}

private PointCollection GetPointCollectionFromEnvelope(Envelope env)
{
 PointCollection pc = new PointCollection();
 pc.Add(new MapPoint(env.XMin, env.YMin));
 pc.Add(new MapPoint(env.XMin, env.YMax));
 pc.Add(new MapPoint(env.XMax, env.YMax));
 pc.Add(new MapPoint(env.XMax, env.YMin));
 pc.Add(new MapPoint(env.XMin, env.YMin));
 return pc;
}

   }
0 Kudos
ThomasSchultz
Deactivated User
Thanks Jennifer!  That answers my question.  I'll try doing it this way.
0 Kudos