Hello
I am trying to query my feature layer when it gets loaded. I found this method on the esri website:
// returns all the graphics from the layer view
view.whenLayerView(layer).then(function(layerView){
layerView.watch("updating", function(val){
if(!val){ // wait for the layer view to finish updating
layerView.queryFeatures().then(function(results){
console.log(results); // prints all the client-side features to the console
});
}
});
});
But this queries through all the features everytime layer gets updated(like dragging, zooming etc.). I just want to query once when it gets loaded. Can someone please help me out with this?
Thanks in advanced
Solved! Go to Solution.
Hi there,
What @KenBuja said. If you are using version 4.23, then please use reactiveUtils instead of watchUtils.
// this will only run once after layerview finishes updating for the first time
view.whenLayerView(layer).then((layerView) => {
reactiveUtils.whenOnce(() => !layerView.updating).then(() => {
console.log("layer finished updating");
});
});
Take a look at this useful blog by @ReneRubalcava about doing things when a layer loads.
async function whenDone() { const layerView = await view.whenLayerView(featureLayer); await watchUtils.whenFalseOnce(layerView, 'updating'); console.log('layerView is done loading and drawing', layerView); }Most of the time, I'm interested in just the first time the layer loads in an application, so I use whenFalseOnce of the watchUtils to check the first time it happens. If you are interested in every time the LayerView is done updating, you could use whenFalse to keep an eye on it.
Hi there,
What @KenBuja said. If you are using version 4.23, then please use reactiveUtils instead of watchUtils.
// this will only run once after layerview finishes updating for the first time
view.whenLayerView(layer).then((layerView) => {
reactiveUtils.whenOnce(() => !layerView.updating).then(() => {
console.log("layer finished updating");
});
});