Using dojo/promise/all I'm attempting to populate an infoTemplate with results from a queryTask which runs later in the script.
Our app returns an XY value from a geocoded address search and queries that value to see if it falls within a series of polygonal features. If it does it should pass a string for each of the three queries.
The query runs and the console doesn't log an error. However, the infoTemplate is blank
:
I've tried to loop through the array results prior to instantiating the infoTemplate but I don't know that that's necessary. Also, I've found that I'm unable to manually set the title of the InfoTemplate using a string.
Code for adding graphic/calling array:
function addPlaceGraphic(item, symbol) {
map.graphics.clear();
var place = {};
var attributes, infoTemplate, pt, graphic;
pt = item.feature.geometry;
place.address = item.name;
place.score = item.feature.attributes.score;
var trashQuery = runPWQuery(pt, trashLayer, "trash");
var yardQuery = runPWQuery(pt, yardWasteLayer, "yardwaste");
var recycleQuery = runPWQuery(pt, recyclingLayer, "recycling");
all([trashQuery, yardQuery, recycleQuery]).then(function (results) {
//receive query responses, update attributes and add graphics
attributes = { trashQuery: pt.trashLayer, recycleQuery: pt.recyclingLayer, yardQuery: pt.yardWasteLayer };
infoTemplate = new InfoTemplate();
infoTemplate.setTitle("Scheduling Information");
infoTemplate.setContent("Trash: ${trashQuery}<br/>Recycling: ${recycleQuery}<br/>Mixed Bulk: ${yardQuery}");
graphic = new Graphic(pt, symbol, attributes, infoTemplate);
//add to map
map.graphics.add(graphic);
map.centerAt(pt);
});
}
Code later in script for queryTask/returning promise:
function runPWQuery(in_geometry , in_fl , in_container_id) {
var query = new esri.tasks.Query();
query.returnGeometry = true;
query.outFields = ["*"];
query.geometry = in_geometry;
var promise = in_fl.queryFeatures(query, function(myresponse, io) {
var temp_val;
var values = [];
var tstr;
for (var il = 0; il < myresponse.features.length; il++) {
if (myresponse.features[il].attributes["MONDAY"] == "Yes") {
temp_val = "Monday";
}
else if (myresponse.features[il].attributes["TUESDAY"] == "Yes") {
temp_val = "Tuesday";
}
else if (myresponse.features[il].attributes["WEDNESDAY"] == "Yes") {
temp_val = "Wednesday";
}
else if (myresponse.features[il].attributes["THURSDAY"] == "Yes") {
temp_val = "Thursday";
}
else if (myresponse.features[il].attributes["FRIDAY"] == "Yes") {
temp_val = "Friday";
}
else {
//temp_val = "Other";
temp_val = myresponse.features[il].attributes["DESCRIPT"];
}
}
var statCount = myresponse.features.length;
if (statCount >= 1) {
$("#" + in_container_id).html(temp_val);
}
else {
$("#" + in_container_id).html("");
}
return temp_val;
}, function (error) {
console.log(dojo.toJson(error, true));
});
//return promise
return promise;
}
function renderPWQuery() {
}
all.then(results)
should return a collection of features. Does it look likeresults
contains the correct information from the three queries?