Hello all,
I'm encountering odd behavior from the queryFeatures method and I can't identify the cause. I'm using the queryFeatures method to highlight features in the featurelayer based on a user's input. However, the response is null only when the user calls the function after the page initializes. E.g. the page loads => user clicks to highlight something => queryFeature response is an empty feature array, but when they try again then the queryFeature method returns the feature in question in the response. There are no features during the first call, but features are successfully returned after each subsequent function call, and I can't figure out why this is happening. The query and the layer which are used in the function are identical each time the method is called. Removing the query argument that is getting passed in also doesn't change the behavior, and I can't identify anything in the react lifecycle which explains this behavior. I'm using react 17.0.1 and I'm using the @arcgis/core package version 4.18.1 for the arcGIS components. I have attached the method + promise handling below.
riverLayer.queryFeatures(riverQuery).then((res) => {
//if res + res.features has length, continue execution
if(res && res.features.length){
//name of highlight variable = highlightTest
if(highlightTest){
highlightTest.remove()
}
//equate the highlightTest variable to the response feature's first index's object id
highlightTest = riverLayer.highlight(res.features[0].attributes.objectid);
}
})
Is there anything that can explain why this only fails to work on the first method call but not any method call after that?