How to return QueryTask results? I read the QueryTask returns a promise and this has to be resolved asynchronous way. I looked at other similar posting and one of them said QueryTask uses Deferred, but I am new to Dojo and I couldn't quite understand how Deferred works. I searched references online as much as I can, but unfortunately, I couldn't find one that displays examples similar to my case. I would appreciate any of your help.
Thank you,
Makiko
Solved! Go to Solution.
After looking a little closer i can see you are really asking how to get your buildingAttributes variable out...
So it would be more like this..
_test:function()
{
queryTask.execute(query, addPointsToMap).then(lang.hitch(this, this._onQueryComplete));
},
_onQueryComplete:function(results)
{
console.debug(results)
}
Your code looks fine (assuming your query is valid) and your results are in the ' results' object..
Do a console.debug on that and you can see the result.
queryTask.execute(query, addPointsToMap).then(function(results){
console.debug(results)
}));
Drew
After looking a little closer i can see you are really asking how to get your buildingAttributes variable out...
So it would be more like this..
_test:function()
{
queryTask.execute(query, addPointsToMap).then(lang.hitch(this, this._onQueryComplete));
},
_onQueryComplete:function(results)
{
console.debug(results)
}
Hi Andrew,
Thank you so much!! I need to familiar with lang.hitch. Your answer is very useful!!
Thanks!!
Line 18 below is where you need to add you console statement.
_getFeatureLayerAttributes: function(){
// Add Building Footprint layer
var queryTask = new QueryTask({
url: "https://services.arcgis.com/.../arcgis/services/...FeatureServer/0"
});
var buildingAttributes = [];
var query = new Query();
query.where = 'Building_Height > -1';
query.outFields = ['OBJECTID', 'Building_Height', 'Z_Min', 'Z_Max'];
queryTask.execute(query).then(function(results){
for(var i = 0; 1 < results.features.length; i++){
var feature = results.features[i].attributes;
var attr = {OBJECTID: feature.OBJECTID, Building_Height: feature.Building_Height,
Z_Min: feature.Z_Min, Z_Max: feature.Z_Max};
buildingAttributes.push(attr); // <--- How to return this???
}
console.log(buildingAttributes); // <--- Right here is where you need to add it
});
//console.log(buildingAttributes) ---> This is not printed
},