Create FeatureLayer out of FeatureSet

4721
4
Jump to solution
12-09-2015 06:13 AM
TimWitt2
MVP Alum

Hey everybody,

Is it possible to create a Feature Layer out of a Feature Set?

In my application I run a queryTask which returns a FeatureSet. I want to use this FeatureSet and feed it to the FeatureTable | API Reference | ArcGIS API for JavaScript dijit. Since this needs a FeatureLayer to work, I was wondering if I could create a Feature Layer out of the FeatureSet?

Any help is appreciated!

Tim

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Tim,

   Absolutely. The API provides for creating a FeatureLayer from a FeatureCollection:

FeatureLayer | API Reference | ArcGIS API for JavaScript | FeatureCollection

var def = new Deferred();
esriRequest({
  url: yourlayerUrl,
  content: {
    f: 'json'
  },
  handleAs: 'json',
  callbackParamName: 'callback'
}).then(lang.hitch(this, function (layerInfo) {
  var featureCollection = {
    layerDefinition: layerInfo,
    featureSet: null
  };
  resultLayer = new FeatureLayer(featureCollection);
  def.resolve({state: 'success', value: layerInfo});
}), lang.hitch(this, function (err) {
  def.resolve({state: 'failure', value: err});
}));

//Now add new features from the query results to it
resultLayer.add(feature);

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Tim,

   Absolutely. The API provides for creating a FeatureLayer from a FeatureCollection:

FeatureLayer | API Reference | ArcGIS API for JavaScript | FeatureCollection

var def = new Deferred();
esriRequest({
  url: yourlayerUrl,
  content: {
    f: 'json'
  },
  handleAs: 'json',
  callbackParamName: 'callback'
}).then(lang.hitch(this, function (layerInfo) {
  var featureCollection = {
    layerDefinition: layerInfo,
    featureSet: null
  };
  resultLayer = new FeatureLayer(featureCollection);
  def.resolve({state: 'success', value: layerInfo});
}), lang.hitch(this, function (err) {
  def.resolve({state: 'failure', value: err});
}));

//Now add new features from the query results to it
resultLayer.add(feature);
TimWitt2
MVP Alum

Thanks Robert.

0 Kudos
TimWitt2
MVP Alum

Hey Robert,

I am not able to run  resultLayer.add(feature) it tells me that resultLayer is not defined. How can I access it within my project?

Thanks,

Tim

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Tim,

   You have to make the resultLayer a global var not a local var so you can use window.resultLayer and not var resultLayer when you initiate it.