Hi There,
I have a set of feature layers that I am querying through an array of queryFeatures. When the queries and run through a Promise.AllSettled, I can loop through the results. I am trying to determine the feature layer id of each set of results. I am having trouble finding an exposed id value. I will summarize an example below. Again, I want to determine which feature layer ID of each result set.
Thank you for looking at this.
Dan
const parcelQuery = {
spatialRelationship: "intersects", // Relationship operation to apply
geometry: queryExtent, // The sketch feature geometry
outFields: ["TheObjectId"], // Attributes to return
returnGeometry: true
};
var promiseArray = [];
//featureLayerArray is an array of the possible feature layers, but we only want to query the ones that are checked with a checkbox
for (const tempFeatureLayer of featureLayerArray) {
tempCheckbox = tempFeatureLayer.id.toString().replace('flqT', 'l');
if (document.getElementById(tempCheckbox).checked) // layer is selected
{
//example definition
tempFeatureLayer.definitionExpression = "UTCstart >= '2020-01' and UTCstart <= '2023-06z'";
promiseArray.push(tempFeatureLayer.queryFeatures(parcelQuery));
console.log('pushed query to array for (tempFeatureLayer.id): ' + tempFeatureLayer.id); // the ID displays correctly
}
}
Promise.allSettled(promiseArray).then((results) =>
results.forEach((result) => {
console.log('result');
console.log('resultID: ' + result.id); // undefined
console.log('result.value.title: ' + result.value.title); //undefined
console.log('result.value.id: ' + result.value.id); //undefined
console.log("result.status: " + result.status); //returns value
console.log('exceededTransferLimit: ' + result.value.exceededTransferLimit.toString()); //returns value
if (result.value.features.length > 0) {
console.log('------ features --------');
const featureList = result.value.features;
for (let i = 0; i < featureList.length; i++) {
console.log('i: ' + i.toString());
console.log(featureList[i].attributes.TheObjectId);
}
console.log('------ end of features --------');
}
})
).catch(error => {
console.log('There is an Error!');
});
Solved! Go to Solution.
It looks like the Promise.allSettled returns the results in the same order as submitted, so I can make a parallel array of what is submitted and loop that array at the same time I'm reading the results. I'm still open to knowing if there is a way to pull the featurelayer id from the results, though. Thanks!
Excellent suggestion! I was looking for that. I'm marking it as the solution.