Hi all, i'm performing a search on multiple feature layers using the .queryFeatures method; Is there anyway for which i can access the layer name from the featureSet? The layers aren't processed in a set order
Thanks
Solved! Go to Solution.
If you aren't already doing so you might want to use dojo/promise/all. dojo/promise/all provides a way to determine when all the queries are done and let you work with the results. We have a sample in the help that shows this approach. Here's a bit of code pulled from the sample that shows how all works. Basically dojo/promise/all accepts an object or an array. In this example we provide an array of deferreds and then we tell it to run the handleQueryResults function when all the queries have completed.
promises = new all([parcels, buildings]); promises.then(handleQueryResults); console.log("created d list"); } function handleQueryResults(results) { console.log("queries finished: ", results); var parcels, buildings; // make sure both queries finished successfully if ( ! results[0].hasOwnProperty("features") ) { console.log("Parcels query failed."); } if ( ! results[1].hasOwnProperty("features") ) { conosle.log("Buildings query failed."); } // results from deferred lists are returned in the order they were created // so parcel results are first in the array and buildings results are second parcels = results[0].features; buildings = results[1].features;
Alternatively you could use an object and provide a key for each. Then you'd access the values using the specified key. More information can be found on this in the dojo doc for dojo/promise/all.
all({ buildings: buildingsQuery, parcels: parcelsQuery }).then(function(results){
Ryan,
I have to admit you have me scratching my head on this question. queryFeatures is a method of a FeatureLayer and thus you will already know which layer (feature layer) invoked the queryFeatures method...
Hi Robert,
Since i'm working with multiple feature layers, the results from each layer doesn't return in the same order to which the layers invoke the queryFeatures method.
If you aren't already doing so you might want to use dojo/promise/all. dojo/promise/all provides a way to determine when all the queries are done and let you work with the results. We have a sample in the help that shows this approach. Here's a bit of code pulled from the sample that shows how all works. Basically dojo/promise/all accepts an object or an array. In this example we provide an array of deferreds and then we tell it to run the handleQueryResults function when all the queries have completed.
promises = new all([parcels, buildings]); promises.then(handleQueryResults); console.log("created d list"); } function handleQueryResults(results) { console.log("queries finished: ", results); var parcels, buildings; // make sure both queries finished successfully if ( ! results[0].hasOwnProperty("features") ) { console.log("Parcels query failed."); } if ( ! results[1].hasOwnProperty("features") ) { conosle.log("Buildings query failed."); } // results from deferred lists are returned in the order they were created // so parcel results are first in the array and buildings results are second parcels = results[0].features; buildings = results[1].features;
Alternatively you could use an object and provide a key for each. Then you'd access the values using the specified key. More information can be found on this in the dojo doc for dojo/promise/all.
all({ buildings: buildingsQuery, parcels: parcelsQuery }).then(function(results){
Hi Kelly,
Thanks for this example, it should resolve my issue.