[GIS] ArcGIS Javascript API – carrying out multiple query tasks

arcgis-javascript-apiquery-task

I have carried out a QueryTask on a map service that returns a polygon when I input a postcode. Within the same service there is an additional layer that allows the user to query a local authority name on. I would like to carry out a querytask on this layer at the same time so that the map returns a polygon relating to the postcode input and also tells me what local authority it is contained within. I will ultimately show the local authority in a separate widget.
Can anyone help please?

Best Answer

Correct me if I'm wrong, but it sounds like the layer with the local authority data is separate from the layer with the post code.

You'll need a second QueryTask for the layer with the local authority data. When the first QueryTask returns the polygon boundary of the post code, pass that polygon geometry into a Query.geometry parameter, and use the new query parameters in the second QueryTask. I've provided a little sample code below.

var postCodeQueryTask = new QueryTask(" /* insert your map service layer url for the post code */ ");
var localAuthQueryTask = new QueryTask(" /* insert map service url for the local authority data */ ");
var postParameters = new Query();

// do stuff to query the post code

// execute the queryTask for the post code
postCodeQueryTask.execute(postParameters, function (featureSet) {
  // do stuff with post code geometry

  // use the geometry to load the local authority data.
  var localAuthParam = new Query();
  localAuthParam.geometry = featureSet.features[0].geometry;
  // do other things to set up your new query

  localAuthQueryTask.execute(localAuthParam, function (localAuthFS) {
    // your featureSet with the local authority data is here.
  });

});
Related Question