Editing using a form.

677
9
06-01-2012 12:05 PM
AmandaHutsel
New Contributor
I am writing an application using the Flex API.  For the editing function of the application, I wish to use a form to add records to a feature class in my geodatabase.  The user will enter all attributes into the form and click a ???save??? button, this will add a new record to the feature class and automatically geocode the address, adding it to the map.  What I???m wanting to know is how I would go about doing this.  I cannot find sample code on the ArcGIS resource page or anywhere else online.  Does anyone have any suggestions as to where I might find sample code for this or how to go about coding this functionality?
Tags (2)
0 Kudos
9 Replies
IvanBespalov
Occasional Contributor III
AttributeInspector (with samples)

You can skin and its child components (fields).
You can choose editable fields vs readonly fields.
You can create own fields (search in this forum for Date Time field for example)

...
0 Kudos
AmandaHutsel
New Contributor
Ivan,
I don't think that the Attribute Inspector will work for me.  They will be adding new records to the database without looking at the map.
Amanda
0 Kudos
IvanBespalov
Occasional Contributor III
Amanda,
1 make query from FeatureService (editable)
2 select feature by clicking on grid row
3 selected feature is shown in attribute inspector (attribute inspector is a form developed by ESRI team for editing attributes)
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" 
      xmlns:esri="http://www.esri.com/2008/ags">
 
 <!-- Adobe Flex SDK 4.6.0 -->
 <!-- ArcGIS API for Flex 3.0 15.03.2012 -->
 <!-- web.zone.ee/bespiva -->
 
 <s:layout>
  <s:VerticalLayout gap="10"
        paddingLeft="10"
        paddingBottom="10"
        paddingRight="10"
        paddingTop="10"/>
 </s:layout>
 
 <fx:Script>
  <![CDATA[
   import com.esri.ags.FeatureSet;
   import com.esri.ags.Graphic;
   import com.esri.ags.events.LayerEvent;
   import com.esri.ags.layers.FeatureLayer;
   import com.esri.ags.layers.supportClasses.Field;
   import com.esri.ags.tasks.supportClasses.Query;
   
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.rpc.AsyncResponder;
   import mx.rpc.Fault;
   import mx.utils.StringUtil;
   
   import spark.components.gridClasses.GridColumn;
   import spark.events.GridSelectionEvent;
   
   [Bindable]
   private var gridSource:ArrayCollection = new ArrayCollection();
   
   [Bindable]
   private var gridColumns:ArrayCollection = new ArrayCollection();
   
   private var queryLayer:FeatureLayer = null;
   
   private function initializeLayer():void
   {
    lblMessage.text = "";
    
    queryLayer = new FeatureLayer(txtServiceUrl.text);
    queryLayer.mode = FeatureLayer.MODE_ON_DEMAND;
    queryLayer.outFields = new Array("*");
    queryLayer.addEventListener(LayerEvent.LOAD, onLayerLoaded, false, 0, true);
    dispatchEvent(new LayerEvent(LayerEvent.LOAD, queryLayer));
   }
   
   protected function onLayerLoaded(event:LayerEvent):void
   {
    //queryLayer.removeEventListener(LayerEvent.LOAD, onLayerLoaded);
    //txtServiceUrl.editable = false;
    if (queryLayer.isEditable)
    {
     lblMessage.text = "Selected layer is editable";
    }
    else
    {
     lblMessage.text = "Selected layer is not valid for editing";
    }
    
    executeQuery();
   }
   
   protected function onExecuteButtonClick(event:MouseEvent):void
   {
    if (queryLayer != null && queryLayer.loaded)
    {
     executeQuery();
    }
    else 
    {
     initializeLayer();
    }
   }
   
   private function executeQuery():void
   {
    var query:Query = new Query();
    query.where = txtWhere.text;
    
    var outs:Array = StringUtil.trim(txtOuts.text).split(",");
    query.outFields = queryLayer.outFields = outs;
    
    queryLayer.queryFeatures(query, new AsyncResponder(onQueryResult, onQueryFault));
   }
   
   protected function onQueryResult(featureSet:FeatureSet, token:Object = null):void
   {
    gridSource = new ArrayCollection();
    var doubleClickMessage:String = "";
    if (queryLayer.isEditable)
    {
     doubleClickMessage = "Click to select feature.";
    }
    lblResultsCount.text = StringUtil.substitute("Found: {0} features. {1}", 
     featureSet.features.length, 
     doubleClickMessage);
    for each(var gr:Graphic in featureSet.features)
    {
     gridSource.addItem(gr.attributes);
    }
    gridSource.refresh();
    
    gridColumns = new ArrayCollection();
    for each (var field:Field in featureSet.fields)
    {
     var gridColumn:GridColumn = new GridColumn(field.name);
     gridColumn.headerText = field.alias;
     gridColumns.addItem(gridColumn);
    }
    gridColumns.refresh();  
    
   }
   
   protected function onQueryFault(fault:Fault, token:Object = null):void
   {
    trace(fault.getStackTrace());
    Alert.show("Query faults.", "Error");
   }
   
   protected function onGetLastResults(event:MouseEvent):void
   {
    if (gridSource) // != null
    {
     var messgae:String = StringUtil.substitute("Last results length is {0}", gridSource.length);
     Alert.show(messgae, "Message");
    }
    else
    {
     Alert.show("No last results found!", "Warning");
    }
   }

   protected function onGridSelectionChange(event:GridSelectionEvent):void
   {
    if (queryLayer.isEditable && queryLayer.layerDetails && gridResults.selectedItem)
    {
     var attributes:Object = gridResults.selectedItem;
     var oid:Number = attributes[queryLayer.layerDetails.objectIdField];
     
     aInspector.featureLayers = [queryLayer];
     
     var q:Query = new Query();
     q.objectIds = [oid];
     queryLayer.mode = FeatureLayer.MODE_SELECTION;
     queryLayer.selectFeatures(q);
    }
   }

  ]]>
 </fx:Script>
 
 
 <s:Panel width="100%" 
    title="Query parameters">
  
  <s:HGroup width="100%"
      height="100%">
   
   <s:VGroup gap="5" 
       paddingLeft="5" 
       paddingTop="5" 
       paddingRight="5" 
       paddingBottom="5" 
       width="100%">
    
    <s:HGroup width="100%">
     
     <s:Label text="Url:" 
        width="150" />
     
     <s:TextInput id="txtServiceUrl"
         width="100%"
         text="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer/2" />
     
    </s:HGroup>
    
    <s:HGroup width="100%">
     
     <s:Label text="Where clause:" 
        width="150" />
     
     <s:TextInput id="txtWhere" 
         width="100%"
         text="1=1" />
     
    </s:HGroup>
    
    <s:HGroup width="100%">
     
     <s:Label text="Out fields (CSV):" 
        width="150" />
     
     <s:TextInput id="txtOuts" 
         width="100%"
         text="*" />
     
    </s:HGroup>
    
    <s:HGroup width="100%">
     
     <s:Button label="Execute" click="onExecuteButtonClick(event)" />
     
     <s:Button label="Last result length" click="onGetLastResults(event)" />
     
    </s:HGroup>
    
   </s:VGroup>
   
   <s:VGroup width="100%"
       height="100%"
       gap="5" 
       paddingLeft="5" 
       paddingTop="5" 
       paddingRight="5" 
       paddingBottom="5">
    
    <s:Label id="lblMessage" />
    
    <esri:AttributeInspector id="aInspector"
                                                        deleteButtonVisible="false" />
    
   </s:VGroup>
   
  </s:HGroup>
  
 </s:Panel>
 
 <s:Panel title="Results" 
    width="100%"
    height="100%">
  
  <s:VGroup gap="5" 
      paddingLeft="5" 
      paddingTop="5" 
      paddingRight="5" 
      paddingBottom="5" 
      width="100%"
      height="100%">
   
   <s:Label id="lblResultsCount" />
   
   <s:DataGrid width="100%"
      height="100%"
      id="gridResults"
      dataProvider="{gridSource}"
      columns="{gridColumns}" 
      selectionChange="onGridSelectionChange(event)"/>
   
  </s:VGroup>
  
 </s:Panel>
 
</s:Application>

I don't think that the Attribute Inspector will work for me.

If I changed your opinion, see the previous topic "AttributeInspector (with samples)"
Anywhere, good luck.
0 Kudos
AmandaHutsel
New Contributor
Thanks for trying to help, but I cannot use the Attribute Inspector because I am not editing points that are already on the map.  I want to add new ones by typing the attributes into a form and then the 'SAVE' button will save them to the geodatabase and geocode the new address at the same time.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Amanda,

   I have some code available from one of my 2012 Dev summit presentations. Look at CrimeEntryWidget.mxml at the following link for an example of a custom form that creates a feature using data entered by the user and that data contains an address that is geocoded to create the feature.

http://gis.calhouncounty.org/devsummit2012/Flex Viewer Files/src/widgets/Sheriff/
0 Kudos
AmandaHutsel
New Contributor
Thanks Robert,

This sounds like exactly what I need.  Unfortualy when I click on the CrimeEntryWidget.mxml I get a 404 error.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Amanda,

   Try right clicking and choosing save as or save target.
0 Kudos
AmandaHutsel
New Contributor
Robert,
For some reason I'm not able to download the file.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Amanda,

   Just go to this url then and grab the whole devsummit2012.zip

http://gis.calhouncounty.org/devsummit2012/
0 Kudos