Select to view content in your preferred language

determine name of feature layer queried from promise.allSettled list

281
3
Jump to solution
04-30-2024 10:51 AM
DanielScholes
New Contributor II

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!');
});

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

You can also get the layer ID for any result that returns at least one feature by looking at the first feature's layer property, and subsequently the layer's id property:

if (result.value.features.length > 0) {
    var layerID = result.value.features[0].layer.id;
    //etc
}

 

View solution in original post

0 Kudos
3 Replies
DanielScholes
New Contributor II

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!

JoelBennett
MVP Regular Contributor

You can also get the layer ID for any result that returns at least one feature by looking at the first feature's layer property, and subsequently the layer's id property:

if (result.value.features.length > 0) {
    var layerID = result.value.features[0].layer.id;
    //etc
}

 

0 Kudos
DanielScholes
New Contributor II

Excellent suggestion! I was looking for that. I'm marking it as the solution.

0 Kudos