Getting Rest URL in QueryTask results

2569
2
Jump to solution
10-13-2015 10:27 AM
SteveClark
New Contributor III

I have a config file consisting of multiple rest endpoint urls and various where clauses. This allows the app to query for a value across multiple rest endpoints (can be 1 or as many as 10) with one or more fields (as many as 4).

I am putting the urls and where clauses in an array and then looping through each, firing off a QueryTask for each:

for (q = 0; q < layerIDs.length; q++) {

  var queryTask = new esriQueryTask(layerIDs);

  var query = new esriQuery();

  query.returnGeometry = true;

  query.outSpatialReference = {wkid:102100};

  query.outFields = [ '*' ];

  query.where = queryWheres;

  queryTask.execute(query, queryResults, queryError);

}

For the results, I am getting the results.features.geometry and throwing the graphics on the map. All this works well

var selections = results.features;

  array.forEach(selections, function(feat) {

  feat.setSymbol(new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 32, null, new Color([175,0,0,0.50])));

  map.graphics.add(feat);

});

if (selections.length == 0) {

  smess.set("value", "No results found for the query.");

} else if (selections.length == 1 && selections[0].geometry.type == "point") {

  map.centerAndZoom( selections[0].geometry, 20);

} else {

  var extent = GraphicsUtils.graphicsExtent(selections);

  map.setExtent(extent.expand(1.25));

}

However, if the results return more than one feature, I put the attributes in a ContentPane within a Container (Tab or Accordion). This I can do but I need to have the title for ContentPane to be something intelligent - preferably the mapserver name. I can use results.displayFieldName but that's nothing useful. I don't see anything in results beyond attributes and geometry.

var resPane = new ContentPane({

  title: ???results.displayFieldName??? + " (" + results.features.length + ")",

  content: grid

});

Is there a way (without running each QueryTask in a promise and having to hardcode each result) that I can get more information in the results from its QueryTask?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Steve,

   Sure all you need to do is to pass the url in your execute.

queryTask.execute(query, queryResults, queryError, queryTask.url);

function queryResults(url, results) {
   console.info(url);
}

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Steve,

   Sure all you need to do is to pass the url in your execute.

queryTask.execute(query, queryResults, queryError, queryTask.url);

function queryResults(url, results) {
   console.info(url);
}
0 Kudos
SteveClark
New Contributor III

Thank you, Robert. I'm just getting into this world and had not known you could pass other parameters. Using an example you stated elsewhere, I came up with this:

queryTask.execute(query, lang.hitch(this, queryResults, layerNames), lang.hitch(this, queryError, queryTask.url));

0 Kudos