I am executing an Identify Task in ArcGIS Javascript. The first time I open my HTML containing this code, I get 'extra' results that should not be in their. When I run the Identify again without reloading the HTML, the results look correct.
Is something being cached on the Deferred? How do I clear out any results so that this code executes without returning erroneous records?
Thanks,
Mele
function executeIdentifyTask (event) {
search.set("value", search.selectedResult.name);
var resultItems = [];
dom.byId("info").innerHTML = "";
event.result.feature;
identifyParams.geometry = event.result.feature.geometry;
identifyParams.mapExtent = map.extent;
identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
var featureAttributes = event.result.feature.attributes;
for (var attr in featureAttributes) {
resultItems.push("<b>" + getFldAlias(attr) + ":</b> " + featureAttributes[attr] + "<br>");
}
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 === 'Brush Collection') {
//alert(feature.attributes['Area']);
resultItems.push("<b>" + "Brush Area: " + "</b> " + feature.attributes['Area'] + "<br>");
}
else if (layerName === 'Refuse Collection') {
//alert(feature.attributes['Collection Day']);
resultItems.push("<b>" + "Refuse Collection Day: " + "</b> " + feature.attributes['Collection Day'] + "<br>");
}
else if (layerName === 'Recycling Collection') {
//alert(feature.attributes['Collection Day']);
resultItems.push("<b>" + "Recycling Collection Day: " + "</b> " + feature.attributes['Collection Day'] + "<br>");
}
//return feature;
dom.byId("info").innerHTML = resultItems.join("");
});
});
}
Solved! Go to Solution.
It looks like my issue was with the identifyParams.tolerance setting. In my code I am using the Search Widget to get a point from our Addresses Feature Class. I then take that point and perform and IdentifyTask against our Solid Waste Route Feature Classes. The first time through the code, the identifyParams.mapExtent is set to map.extent; which is the full city. The tolerance was selecting nearby polygons.
I am not showing the map I am using in my code so maybe this is impacting things, but decreasing the tolerance setting looks to have solved my issue.
Mele
Mele,
What do you mean extra results? I would be helpful to post screenshots of the extra vs the expected as this will help identify the issue better.
It looks like my issue was with the identifyParams.tolerance setting. In my code I am using the Search Widget to get a point from our Addresses Feature Class. I then take that point and perform and IdentifyTask against our Solid Waste Route Feature Classes. The first time through the code, the identifyParams.mapExtent is set to map.extent; which is the full city. The tolerance was selecting nearby polygons.
I am not showing the map I am using in my code so maybe this is impacting things, but decreasing the tolerance setting looks to have solved my issue.
Mele