1

Currently i'm working on a Arcgis based drawing tool. What we've done so far is create a system where we can easily create local feauture layers and edit those with the standard Editor Widget. Drawing seems to work perfectly, however I've been having problems with fields within those objects.

Can someone explain why the fields defined in my local layer do show up after drawing an object with this non-amd code example.

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>demo</title>
    <link rel="stylesheet" href="http://js.arcgis.com/3.12/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="http://js.arcgis.com/3.12/esri/css/esri.css">
    <style>
      html, body {
        height: 100%;
        width: 100%;
        margin: 0; 
        padding: 0;
        overflow:hidden;
        background:#fff;
      }
  </style>
    <script src="http://js.arcgis.com/3.12/"></script>
    <script>
      dojo.require("esri.map");
      dojo.require("esri.dijit.editing.Editor");
      var map;
      function init() {

        map = new esri.Map("map", { 
          basemap: "topo",
          center: [-117.735, 34.356],
          zoom: 13, 
          slider: false
        });
              dojo.connect(map,"onLayerAddResult", initEditor);

        var json = {
                  layerDefinition: {
                      "geometryType": 'esriGeometryPolygon',
                      "fields": [{
                          "name": "Buff",
                          "type": "esriFieldTypeString",
                          "alias": "Buffer Distance"
                      }, {
                          "name": "field_test",
                          "type": "esriFieldTypeOID",
                          "alias": "Field test",
                          "editable": true,
                          "length": 25,
                      }, {
                          "name": "Asdd",
                          "type": "esriFieldTypeString",
                          "alias": "asdf"
                      }, {
                          "name": "Asdd2",
                          "type": "esriFieldTypeString",
                          "alias": "asdf2"
                      }],
                      "type": "Feature Layer",
                      "templates": [{
                          "name": 'test',
                          "description": "",
                          "drawingTool": 'esriFeatureEditToolPolygon',
                          "prototype": {
                              "attributes": {
                                  "field_test": "test",
                                  "Asdd": "test2"
                              }
                          }
                      }],
                  },
                  featureSet: null
              };

        layer = new esri.layers.FeatureLayer(json,{
          mode: esri.layers.FeatureLayer.MODE_SNAPSHOT, //QUERY_SELECTION is working as well
          outFields: ['*'],
          id: 'test'
        });
        layer.setEditable(true);

        map.addLayer(layer);
}
        var layers=[];    
        var i =1;
              function initEditor(evt) {
                  var layer = evt;
                  if (!layer.url) {
                      layers.push({
                          featureLayer: layer
                      });
                  }
                  if (map['_layerSize'] == i) {
                      var settings = {
                          map: map,
                          layerInfos: layers
                      };
                      var params = {
                          settings: settings
                      };     
                      var myEditor = new esri.dijit.editing.Editor(params, 'templatePickerDiv');
                      myEditor.startup();
                  }
                  i++;
           }
      dojo.ready(init);
    </script>
  </head>
  <body class="claro">    
      <div id="map"></div>
        <div id="templatePickerDiv"></div>
    </div>
  </body>
</html>

But when I try to do exactly the same thing but with loading through AMD it doesn't work :(

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>demo</title>
    <link rel="stylesheet" href="http://js.arcgis.com/3.12/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="http://js.arcgis.com/3.12/esri/css/esri.css">
    <style>
      html, body {
        height: 100%;
        width: 100%;
        margin: 0; 
        padding: 0;
        overflow:hidden;
        background:#fff;
      }
  </style>
    <script src="http://js.arcgis.com/3.12/"></script>
    <script>
      require([
          'esri/map',
          'esri/dijit/editing/Editor',
          'esri/layers/FeatureLayer',
          'dojo/ready'
      ], function(Map, Editor, FeatureLayer, ready) {
          var map;
          ready(function() {

              map = new Map("map", {
                  basemap: "topo",
                  center: [-117.735, 34.356],
                  zoom: 13,
                  slider: false
              });
              dojo.connect(map,"onLayerAddResult", initEditor);

              var json = {
                  layerDefinition: {
                      "geometryType": 'esriGeometryPolygon',
                      "fields": [{
                          "name": "Buff",
                          "type": "esriFieldTypeString",
                          "alias": "Buffer Distance"
                      }, {
                          "name": "field_test",
                          "type": "esriFieldTypeOID",
                          "alias": "Field test",
                          "editable": true,
                          "length": 25,
                      }, {
                          "name": "Asdd",
                          "type": "esriFieldTypeString",
                          "alias": "asdf"
                      }, {
                          "name": "Asdd2",
                          "type": "esriFieldTypeString",
                          "alias": "asdf2"
                      }],
                      "type": "Feature Layer",
                      "templates": [{
                          "name": 'test',
                          "description": "",
                          "drawingTool": 'esriFeatureEditToolPolygon',
                          "prototype": {
                              "attributes": {
                                  "field_test": "test",
                                  "Asdd": "test2"
                              }
                          }
                      }],
                  },
                  featureSet: null
              };

              layer = new FeatureLayer(json, {
                  mode: FeatureLayer.MODE_SNAPSHOT,
                  outfields: ["*"],
                  id: 'test'
              });
              layer.setEditable(true);

              map.addLayer(layer);
          });

            var layers=[];    
            var i =1;
              function initEditor(evt) {
                  var layer = evt;
                  if (!layer.url) {
                      layers.push({
                          featureLayer: layer
                      });
                  }
                  if (map['_layerSize'] == i) {
                      var test = window.layers;
                      var settings = {
                          map: map,
                          layerInfos: layers
                      };
                      var params = {
                          settings: settings
                      };     
                      var myEditor = new Editor(params, 'templatePickerDiv');
                      myEditor.startup();
                  }
                  i++;
           }
      });
    </script>
  </head>
  <body class="claro">    
      <div id="map"></div>
        <div id="templatePickerDiv"></div>
    </div>
  </body>
</html>    

Is this an arcgis bug? Or am i doing something wrong? I would like to load everything through AMD as this is the way we've set everything up so far. (It works in combination with AngularJS)

1
  • I have spent some time trying this. Looks like after myEditor.startup() in the AMD code, the layers[0].fieldInfos is an empty array, whereas for the other code the fields exists. I manually added the fieldInfos, and then it worked. But that is probably not how you would want to approach it. Feb 10, 2015 at 20:46

1 Answer 1

2

you aren't using the appropriate mixed casing for 'outFields' in your AMD FeatureLayer constructor.

layer = new FeatureLayer(json, {
  ...
  outFields: ["*"],
  ...
});

this is what is causing the problem you noticed in your AMD application downstream.

3
  • Good catch! I spent some time trying to figure this one out. Feb 17, 2015 at 2:47
  • took me awhile to see it too :) Feb 17, 2015 at 3:17
  • Thank you so much! A colleague found the missing capital at almost the same time as you did. Such a small but stupid mistake, I'm happy to report that our code is working as expected.
    – bnew
    Feb 19, 2015 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.