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
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);
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.
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,
Thanks Robert.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.