Select to view content in your preferred language

Retrieve layer name when using .queryFeatures method

1512
4
Jump to solution
08-26-2014 09:49 AM
RyanSmith1
New Contributor III

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

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor

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){

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

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...

0 Kudos
RyanSmith1
New Contributor III

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.

0 Kudos
KellyHutchins
Esri Frequent Contributor

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){

RyanSmith1
New Contributor III

Hi Kelly,

Thanks for this example, it should resolve my issue.

0 Kudos