Hello,
I have an app where i need to save the results on a custom array. They come from the deferred identify task when an user clicks on the map.
I have the following:
mapp.on('click', (event)=>{
var identifyTask, identifyParams;
identifyTask = new IdentifyTask(layers.read_dynamic_ap());
identifyParams = new IdentifyParameters();
identifyParams.tolerance = 10;
identifyParams.returnGeometry = true;
identifyParams.layerIds = [0, 1];
identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
identifyParams.width = mapp.width;
identifyParams.height = mapp.height;
identifyParams.geometry = event.mapPoint;
identifyParams.mapExtent = mapp.extent;
var deferred = identifyTask
.execute(identifyParams)
.addCallback(function (response){
return arrayUtils.map(response, function (result) {
var feature = result.feature;
var layerName = result.layerName;
feature.attributes.layerName = layerName;
if(layerName === 'Cars'){
var carsTemplate= new InfoTemplate("ID: ${id}",
"Car: ${car} <br />" +
"Type: ${type}<br /> ");
feature.setInfoTemplate(carsTemplate);
}
return feature;
});
});
mapp.infoWindow.setFeatures([deferred]);
mapp.infoWindow.show(event.mapPoint);
//see content :
console.log("hello def", deferred.results);
});
In the same point could be more than 1 result, so i want to save them all in a custom array made for me for special purposes.
When i see the content coming for that deferred var i have this:
console.log("hello def", deferred);
Where i can see there is a property called results (its an array).
I tried to put in console.log(deferred.results) but i get undefined.
There is a way how to save those results? What im doing wrong?
Thanks in advice.
Evelyn,
Your
console.log("hello def", deferred.results);
is getting called before the deferred is returned. That is why it is undefined. You need to set an array in your code to the results inside your call back function. Another way is to use
deferred.then(function(results){