Select to view content in your preferred language

FeatureLayer from FeatureCollection

6854
15
Jump to solution
12-15-2015 05:53 PM
LefterisKoumis
Frequent Contributor

I get the Converting circular structure to JSON error when I create the feature layer, thislayer. Any ideas? Thank you..

var requestHandle = esriRequest({

            "url": myurl, //I set the variable to a featureservice url

            "content": {

              "f": "json"

            },

            "callbackParamName": "callback"

          });

 

          myfields =requestHandle.then(this.requestSucceeded, this.requestFailed);

 

   var layerDefinition = {

        "geometryType": "esriGeometryPoint",

        "fields": myfields,

         "objectIdField": "OBJECTID",

  }     

  var featureCollection = {

  layerDefinition: layerDefinition,

  featureSet: myfeatureSet  //it's derived from a query

  };

  var thislayer = new esri.layers.FeatureLayer(featureCollection, {

  id: "query layer",

        mode: FeatureLayer.MODE_SNAPSHOT,

  outFields:["*"]}

  );

 

  this._openResultInAttributeTable(thislayer);

      

      },

      requestSucceeded:function(response, io){

            fields = array.map(response.fields);

  return fields;

   },

        requestFailed: function(error, io){

  console.log("got an error");       

  }, 

0 Kudos
15 Replies
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

  Your code was a mess. You need to spend more time cleaning up your code so you don't get confused in there. Here is a pretty clean working version.

0 Kudos
LefterisKoumis
Frequent Contributor

yes, i agree. Thank you for you kind words and your time. I have an observation. The selectInBuffer is called twice, creating two tabs on the Attribute table, one is with the field names and one one without it.

Thank you again.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

     I have tested the exact code that I provided you several more times and it only opens one tab.

0 Kudos
LefterisKoumis
Frequent Contributor

I just copied the code you gave me and I got this. This is bizarre. One of the screenshot (see below), shows the first tab with the field names and the second tab without the field names.  So, I placed in the "theselectInBuffer"  a console.log and it was called twice, and hence calling the attribute table twice.

selectInBuffer: function (results) {

        array.map(results, lang.hitch(this, function(feature){

          this.thelayer.add(feature);

        }));

  console.log("sign1");

        this._openResultInAttributeTable(this.thelayer);

      },

output:

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   That is bizarre. I added a console.info to the selectInBuffer function as well and it is only called once. It must be in how you are using the widget in your app. Do you accidentally have it added twice in the config.json or something?

0 Kudos
LefterisKoumis
Frequent Contributor

That was it. Thank you.

0 Kudos