Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I use a FeatureLayer created from the featureCollection. I also use esri.dijit.editing.Editor to add a feature to the map. Every time feature has been added to this layer I want to send it to my remote service using rest API. I tried to use FeatureLayer's onEditsComplete event:

<!doctype html>
<html>
  <head>
    <title>...</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.2/js/dojo/dijit/themes/claro/claro.css">
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.2"></script>
    <script type="text/javascript" language="Javascript">
      dojo.require("esri.map");
      dojo.require("esri.layers.FeatureLayer");
      dojo.require("dijit.form.Button");      
      dojo.require("esri.dijit.editing.Editor-all");
      var map;
      var startExtent = new esri.geometry.Extent({"xmin":-12505511,"ymin":2230016,"xmax":-3699965,"ymax":8100380,"spatialReference":{"wkid":102100}});
      var featureLayer;

      function init() {
        map = new esri.Map("mapDiv",{ extent: startExtent });
        //create and add new layer
        var layer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
        map.addLayer(layer);

        var jsonFS = {
          "displayFieldName": "Name",
          "fieldAliases": {
              "Name": "Name"
          },
          "geometryType": "esriGeometryPoint",
          "spatialReference": {
              "wkid": 102100 //WGS_1984_Web_Mercator_Auxiliary_Sphere
          },
          "fields": [{
              "name": "Name",
              "type": "esriFieldTypeOID",
              "alias": "Name"
          }],
          "features": [{
              "attributes": {
                "OBJECTID": "1",
                "Name": "1"
              },
              "geometry": {
                  "x": -8919439.31450887,
                  "y": 4928270.761925456
              }
          },
          {
              "attributes": {
                "OBJECTID": "2",
                "Name": "2"
              },
              "geometry": {
                  "x": -8155495.379532158,
                  "y": 5075380.311392084
              }
          }]
        };
        console.log(jsonFS.features);
        var fs = new esri.tasks.FeatureSet(jsonFS);

        var featureCollection = {
          layerDefinition: {
            "geometryType": "esriGeometryPoint",
            "fields": [
            {
                "name": "OBJECTID",
                "type": "esriFieldTypeOID",
                "alias": "OBJECTID"
            },
            {
              "name": "Name",
              "type": "esriFieldTypeString",
              "alias": "Name"
            }
            ]
          },
          featureSet: fs
        };

        featureLayer = new esri.layers.FeatureLayer(featureCollection, {
          mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,
        });
        map.addLayer(featureLayer);
      }
      dojo.ready(init);

      function initEditor() {
        if (featureLayer === 'undefined' || featureLayer === null)
        { return; }

        var templatePicker = new esri.dijit.editing.TemplatePicker({
          featureLayers: [featureLayer],
          rows: 'auto',
          groupingEnabled:false,
          columns: 1
        },'editorDiv');
        templatePicker.startup();

        var layerInfos = [{
          'featureLayer': featureLayer,
          'showAttachments':true,
          'showDeleteButton':true,
          'fieldInfos':[
            {'fieldName':'Name','label':'Name'}
          ]
        }];   

        var settings = {
          map: map,
          enableUndoRedo:true,
          templatePicker: templatePicker,
          layerInfos: layerInfos
        };

        var params = {settings: settings};

        var editorWidget = new esri.dijit.editing.Editor(params);
        editorWidget.startup();

        map.infoWindow.resize(260,215);

        dojo.connect(featureLayer, "onEditsComplete", function(edits, updates, deletes) {
            var a = 5;
            //there I want to send request to the service
            //var xhrArgs = {
            //  url: "http://XXXX/add",
            //  handleAs: "json",
            //  preventCache: true,
            //  content: {
            //      geometry: "....",
            //      text: "...."
            //  }
            //};
            //dojo.xhrGet(xhrArgs);
        });
    }   

    </script>
  </head>
  <body class="claro">
    <div id="mapDiv" style="width:900px; height:600px; border:1px solid #000;"></div>
    <div id="editorDiv"></div>
    <button dojoType="dijit.form.Button" onclick="initEditor();">
        Set up editor
    </button>
  </body>
</html>

But it fires before user has entered information in the dialog created when user clicks on the map. So it seems useless. I tried onAddAttachmentComplete event but it never fires. Do you know how to specify that mentioned action shall be done after user entered text in the editor's dialog?

share|improve this question
Can you provide some more context on how this all works? What is the dialog you're using? Are you using the editor widget? A more complete code sample or even entire html page would be helpful. – Derek Swingley May 4 '11 at 15:48

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.