I know I need to have some sort of Deferred defined here, but I'm not sure where to insert it. I have a point layer with school names and school districts. I have a table that has the school districts and names again, plus results of testing for radon.
I do not have this set up as a relate in my service. Names of schools are not unique across the state, and I have no unique ID provided in that table. Instead, I need to be able to run a query on the table, and before showing the infoWindow, I want to capture the tabular data too and append it to the data coming from the graphic (name, address, city etc).
Right now I only have one year's worth of data per school, but there is also the potential for additional years as time goes by.
My InfoTemplate definition:
//infoTemplates
var schoolPtInfoTemplate = new InfoTemplate("Test Results");
schoolPtInfoTemplate.setContent(myInfoTemplate.schoolInfoContent);my pointLayer
app.pointLayer = new FeatureLayer (pathName+"/arcgis/rest/services/radonSchool/MapServer/0", {
id: "schoolLayer",
outFields: ["*"],
infoTemplate: schoolPtInfoTemplate
});//myInfoTemplate
define ([
"dojo/dom-construct",
"dojo/on",
"dojo/dom",
"dojo/Deferred" ,
"dojo/_base/array",
"dojo/_base/lang",
"dojo/query",
"dojo/date/locale",
"dojo/number",
"esri/tasks/query",
"esri/tasks/QueryTask",
"js/myRelates"
] , function (domConstruct,on,dom,Deferred,arrayUtils, lang,query,locale,number, Query,QueryTask, myRelates) {
return {
schoolInfoContent: function(graphic){
var currentGraphic = graphic;
var formatString = "";
var oid = graphic.attributes.OBJECTID;
var ctyDist = graphic.attributes.CtyDist;
var locTest = graphic.attributes.Loc_Code;
var nm = graphic.attributes.Facility
formatString ="<b>" + graphic.attributes.Facility + "</b><br/>"
+ graphic.attributes.Address + "<br/>"
+ graphic.attributes.City+ ", MO " + graphic.attributes.ZIP
var addedString = findSchRelatedRecords (nm, ctyDist);
formatString += addedString;
function findSchRelatedRecords (nm, id){
var schQuery = new Query;
var queryTask = new QueryTask(app.testTable.url);
var whereClause = "Facility = '" + nm + "' AND Dist_Code = '" + id + "'";
schQuery.where = whereClause;
schQuery.returnGeometry = false;
schQuery.outFields = ['*'];
queryTask.execute(schQuery, lang.hitch(this,function(results){
var addedString = " ";
var len = results.features.length;
if (len = 0) {
addedString += "No test results found";
}else {
arrayUtils.forEach(results, function (r) {
addedString += "Start Year: " + r.attributes.ScholYearStart;
});
}
})
);
return addedString;
}
return formatString;
}
}
});