Select to view content in your preferred language

How to use <esri:Editor> in flex viewer

2951
10
04-08-2011 10:49 AM
LeiZhou
Deactivated User
I need to create a <esri:Editor> in my widget in flex viewer. I need to edit the map in flex viewer (See code); the sample is too complicated and I need a simple one. 

<esri:Editor id="myEditor"
geometryService="{new GeometryService('http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer')}"
map=???
toolbarVisible="true"/>

I don't know how set the property "map".
In widget, there is no code like <esri:Map id="myMap">, so that I can set map="{myMap}"

How do I let my Editor connect to <esri:Map> so that I can edit feature service? Should I go to config.xml file to get the operation layer ? Thanks a lot!
Tags (2)
0 Kudos
10 Replies
BjornSvensson
Esri Regular Contributor
Any widget that extends BaseWidget will have access to the main map as "map". See some examples below:
//From the Edit widget:
editor.map = map;


//From the Data Extract widget:
map.addLayer(graphicsLayer);
...
gp.processSpatialReference = map.spatialReference;
gp.outSpatialReference = map.spatialReference;
0 Kudos
LeiZhou
Deactivated User
What if I just want to add an editor in the sample widget-HellowWorld?

When I add the following codes, how do I know the main map's featureLayer's name/id?  And the url has to be the operation layer's url, right?  Thanks!


<esri:Editor id="myEditor"
                     geometryService="{new GeometryService('http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer')}"
                     map="{map}"
                     toolbarVisible="true"/>




Any widget that extends BaseWidget will have access to the main map as "map". See some examples below:
0 Kudos
BjornSvensson
Esri Regular Contributor
I don't think you need to know the name/id/url of the feature layers.  Look at the Edit widget:
editor.featureLayers = featureLayers;
// where featureLayers is a local (not global) variable


Depending on your use case, you wouldn't use all the feature layers, only the editable feature layers.  Also, when a layer is turned on/off, your widget probably would want to know.  The Edit Widget already takes care of many such scenarios.

Maybe take a step back and explain what you are trying to do in more details.  I'm curious why the EditWidget, either as is, or modified, wouldn't be a better starting point than the HelloWorld widget...
0 Kudos
LeiZhou
Deactivated User
Here is my code, in the widget, after I click, nothing happens.  There should be a point added to the map, but that does not happen.  I don't know why.  Thanks!

<viewer:BaseWidget 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"
                   xmlns:viewer="com.esri.viewer.*"
   initialize="init(event)" >
 <fx:Script>
        <![CDATA[
   
   import com.esri.ags.FeatureSet;
   import com.esri.ags.Graphic;
   import com.esri.ags.events.FeatureLayerEvent;
   import com.esri.ags.events.MapEvent;
   import com.esri.ags.events.MapMouseEvent;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.tasks.QueryTask;
   import com.esri.ags.tasks.supportClasses.Query;
   import com.esri.ags.utils.WebMercatorUtil;
   
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.events.FlexEvent;
   import mx.rpc.AsyncResponder;
   import mx.rpc.events.ResultEvent;
   
   import com.esri.ags.Graphic;
   import com.esri.ags.events.AttributeInspectorEvent;
   import com.esri.ags.events.FeatureLayerEvent;
   import com.esri.ags.events.MapMouseEvent;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.layers.supportClasses.FeatureEditResult;
   import com.esri.ags.layers.supportClasses.FeatureEditResults;
   import com.esri.ags.layers.supportClasses.Field;
   
   import mx.controls.Alert;
   import mx.rpc.AsyncResponder;
   import mx.rpc.Fault;
   import mx.rpc.events.FaultEvent;
   
   
   private function init(event:FlexEvent):void
            {         myEditor.featureLayers=[points];
                
            }
   
   
   
        ]]>
    </fx:Script>
 
 <fx:Style>
  @namespace s "library://ns.adobe.com/flex/spark";
  @namespace esri "http://www.esri.com/2008/ags";
  @namespace components "com.esri.ags.components.*";
  
  components|InfoWindow
  {
   background-color : #FFFFFF;
   border-thickness : 2;
  }
 </fx:Style>
 

 
 <fx:Declarations>
  <esri:GeometryService id="myGeometryService" url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/>
  
  </fx:Declarations>
 
 
 <viewer:WidgetTemplate id="helloWorld"
                           width="100%" height="100%" 
         >
        <viewer:layout>
            <s:HorizontalLayout />
  </viewer:layout>
  
  <esri:Editor id="myEditor"
      geometryService="{myGeometryService}"
      map="{map}"
      toolbarVisible="true"/> 
  
     
  <esri:FeatureLayer id="points"
         mode="snapshot"
         outFields="*"
         url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer/0"/>

    
      </viewer:WidgetTemplate>

</viewer:BaseWidget>
I don't think you need to know the name/id/url of the feature layers.  Look at the Edit widget:
editor.featureLayers = featureLayers;
// where featureLayers is a local (not global) variable


Depending on your use case, you wouldn't use all the feature layers, only the editable feature layers.  Also, when a layer is turned on/off, your widget probably would want to know.  The Edit Widget already takes care of many such scenarios.

Maybe take a step back and explain what you are trying to do in more details.  I'm curious why the EditWidget, either as is, or modified, wouldn't be a better starting point than the HelloWorld widget...
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Steven,

   You can't add a FeatureLayer to the widgetTemplate it has to be added to the map object. You could do this using ActionScript but I have to echo Bjorn's question as to why are you attempting to do this on your own and not beginning with the editor widget...?
0 Kudos
LeiZhou
Deactivated User
Because I have no clue how to modify the EditWidget in viewer.  For instance, I need my own feature layer to appear instead of �??Incident Points�?� or �??Incident Areas�?�.  I go to EditWidget.mxml, go to function populateEditor(array:Array):void, then I change the last statement from editor.featureLayers = featureLayers; ------ to  ---------
editor.featureLayers=[points];

Points is the layer as the following, I have no clue how to add this layer to EditWidget.
1. <esri:FeatureLayer id="points"
2. mode="snapshot"
3. outFields="*"
4. url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer/0"/>

The �??points�?� layer can now appear on the map, but can not draw anything.  I have no instruction like how to modify EditWidget. Thanks a lot!


Steven,

   You can't add a FeatureLayer to the widgetTemplate it has to be added to the map object. You could do this using ActionScript but I have to echo Bjorn's question as to why are you attempting to do this on your own and not beginning with the editor widget...?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Steven,

   Have you looked at the concepts-widgets-editorwidget page of the viewer here:

http://help.arcgis.com/en/webapps/flexviewer/help/widgets/edit_widget.htm

By default, each visible feature layer from the operational layers in the Viewer application is editable with the Edit widget. The widget will automatically know what types of features can be created/edited based on the layer's defined feature template. Feature layers can be made ineditable by specifying the layer name in the widget's <excludelayer> tag.
0 Kudos
LeiZhou
Deactivated User
Hi, Robert,

Yes, I read it and it is very helpful. Thanks!

I just feel I have some details that I don't know when customerizing EditWidget.  For example, I want to set toolbarVisible of <esri:Editor>,  toolbarVisible="true";

After add the above statement to the following code inside EditWidget.mxml, the toolbar still does not show up in the widget.  How do I handle it? Is there any instruction I can follow? Thanks again!

 <viewer:WidgetTemplate width="300" height="300"
                           closed="widgetClosedHandler(event)"
                           minHeight="300"
                           minWidth="300"
                           minimized="widgetMinimizedHandler(event)"
                           open="widgetOpenedHandler(event)">
        <viewer:layout>
            <s:VerticalLayout paddingLeft="5" paddingTop="10"/>
        </viewer:layout>
        <s:Label text="{getDefaultString('selectTemplateText')}"/>
        <mx:Spacer/>
        <esri:Editor id="editor"
                     width="100%" height="100%"
                     geometryService="{geometryService}"
         toolbarVisible="true"/>
    </viewer:WidgetTemplate>


Steven,

   Have you looked at the concepts-widgets-editorwidget page of the viewer here:

http://help.arcgis.com/en/webapps/flexviewer/help/widgets/edit_widget.htm
0 Kudos
GarrettMoeller
Deactivated User
Greetings,
I am also trying to get the editor to work.
I am using the compiled version.
None of my feature layers are showing up for this particular widget.
I am wondering if you have to enable "Feature Access" when publishing the mapservice.
This would mean that it would have to be an SDE setup in order to use this widget.

Otherwise, I don't understand why it is not working.
The edit box shows up, with no layers to choose from - just a blank box that says
"select template to create feature"

Thanks
0 Kudos