0

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?

asked Jun 30, 2015 at 9:04

3 Answers 3

1

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.
 });
});
answered Jul 1, 2015 at 14:23
1

Take a look at this sample that shows how to work with queries of different layers or services. It also uses Dojo Promise function to handle the results from executing more than one query.

answered Jul 1, 2015 at 15:53
0

I've inclued the code I've done to return the postcode geometry but I'm still unsure about where I should add the 2nd queryTask to pass the geometry from the postcode to the local authority area. I'm gussing the 2nd queryTask should be included within the first so that it doesnt run before the 1st queryTask has finished?? Thanks var queryTask = new QueryTask("http://rest/services/live/SEARCH/MapServer/2");

 var query = new Query();
 query.returnGeometry = true;
 query.outFields = [
 "POSTCODE"
 ];
 on(dom.byId("execute"), "click", execute);
 function execute() {
 query.text = dom.byId("Postcode").value;
 queryTask.execute(query, showResults);
 }
 function showResults(results) {
 var resultItems = [];
 var resultCount = results.features.length;
 for (var i = 0; i < resultCount; i++) {
 var featureAttributes = results.features[i].attributes;
 var graphic = results.features[i];
 graphic.setSymbol(symbol);
 map.graphics.add(graphic);
 //var queryTask2 = new QueryTask("http://rest/services/live/SEARCH/MapServer/15");
 //query2 = new.esri.tasks.Query();
 //query2.returnGeometry - false;
 //query2.where = ""
 var strNum = 100;
 var newExtent = graphic.geometry.getExtent();
 newExtent.xmin = newExtent.xmin - strNum;
 newExtent.ymin = newExtent.ymin - strNum;
 newExtent.xmax = newExtent.xmax + strNum;
 newExtent.ymax = newExtent.ymax + strNum;
 map.setExtent(newExtent);
 for (var attr in featureAttributes) {
 resultItems.push("<b>" + attr + ":</b> " + featureAttributes[attr] + "<br>");
 }
 resultItems.push("<br>");
 }
 dom.byId("info").innerHTML = resultItems.join("");
 }
 dom.byId("results")
 function addToMap(result) {
 debugger;
 }
 });
answered Jul 6, 2015 at 13:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.