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
Solved! Go to Solution.
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);
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);
Thanks Robert.
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
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.