Select to view content in your preferred language

FeatureLayer editing - Add feature

1355
2
03-03-2011 06:18 AM
DonFreeman
Emerging Contributor
The sample shown at http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitEditorWidget demonstrates how to add and delete features from a FeatureLayer but is very incomplete in its description. For example, I have a map with 4 editable FeatureLayers. I am able to edit their attributes successfully. However, after creating a Geometry service and adding the EditorWidget to the page, the widget appears empty with no symbols and no apparent functionality.

So my question is, what's happening here and is there a better description somewhere on how to set this up?
Thanks

errata - Please disregard my original request. (I had the layer name spelled wrong. 20 whacks with a wet noodle) But I do have another question. How do I customize this thing? Like the presentation of the fields to be edited.
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
From the sample link you provided, the EditorWidget is set up this way:

<esri:EditorWidget x:Name="MyEditorWidget" 
   Map="{Binding ElementName=MyMap}"
Width="300"  
AutoSelect="False" 
   GeometryServiceUrl="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"
ShowAttributesOnAdd="True"  
Loaded="EditorWidget_Loaded"/> 


The EditorWidget properties that need to be set at minimum are Map and GeometryServiceUrl. However, if your map does not contain GraphicsLayer or FeatureLayer with ID, all buttons will be disabled. If GeometryServiceUrl has not been specified then commands that may need them (Add, Union, Cut, Reshape, EditVertices) will also be disabled.

As for your other question, if you want to customize the look and feel of the EditorWidget, it can be done the same way as the other controls. Please see this blog post: http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2010/05/20/Use-control-templates-to-customize....

The FeatureDataForm that is displayed on a ChildWindow after an Add is completed or DisplayAttribute is clicked use the default style.

If you want more control of how the fields are displayed, you can do the following:
1. Set EditorWidget ShowAttributesOnAdd to False.
2. Subscribe to EditorWidget.EditCompleted
3. Use customized FeatureDataForm or use your own UserControl to display attributes.
private void MyEditorWidget_EditCompleted(object sender, Editor.EditEventArgs e)
{
 if (e.Action == Editor.EditAction.Add)
 {
  foreach (Editor.Change change in e.Edits)
  {
   if (change.Layer != null && change.Layer is FeatureLayer && change.Graphic != null)
   {
    FeatureLayer featureLayer = change.Layer as FeatureLayer;
    ShowAttributeForm(featureLayer, change.Graphic);
    break;
   }
  }
 }
}

private void ShowAttributeForm(FeatureLayer featureLayer, Graphic graphic)
{
 ChildWindow window = new ChildWindow();
 FeatureDataForm form = new FeatureDataForm()
 {
  GraphicSource = graphic,
  FeatureLayer = featureLayer,
  IsReadOnly = featureLayer.IsReadOnly
 };
 window.Content = form;
 form.EditEnded += (s, e) => { window.Close(); };
 window.Show();
}


The code in red above can be replaced with another UserControl or maybe set FeatureDataForm style.
0 Kudos
DonFreeman
Emerging Contributor
Thanks Jenn.
Very helpful.
0 Kudos