Title: ESRI JS API 4x Graphics layer on load function
Tags: arcgis-javascript-api
Question: I am working on developing a webapp using ESRI JS API 4.x. My main requirement is to search some address, zoom on the address, create a buffer, using that that buffer query data from a feature layer and show all intersecting features as graphics on map. I am able to achieve all this successfully.
Next requirement is to take a screenshot of map in two different basemaps after the intersecting features are loaded on map.
Previously we used to have a graphics layer on load type function which triggers when all the graphics are added on map. In API version 4.x i understand now mostly these type of events are handled using watch utils and observing value of specific variables such as graphics layer loaded.
My issue is, these events trigger first and then graphics are added on map which is killing the entire purpose. Till now i have used following, in all of these my graphics layer status is always loaded even though the graphics which i added are not showing on the map.
My only requirement is to know when graphics are visible on map.
watchUtils.whenFalse(view, &quot;updating&quot;, async () =&gt; {
console.log('---Watch: view Updating =&gt; Graphics Layer Load Stauts : ' + graphicsLayer.loadStatus)
console.log('---Watch: view Updating =&gt; toggle.activeBasemap.loadStatus ' + toggle.activeBasemap.loadStatus)
console.log('map.basemap' + map.basemap)
View =&gt; Updating
view.watch('updating', function (evt) {
if (evt === true) {
domClass.add('loadingDiv', 'visible');
console.log('======graphicsLayer.loadStatus')
console.log(graphicsLayer.loadStatus)
console.log('---View Watch Updating Started');
} else {
domClass.remove('loadingDiv', 'visible');
console.log('======graphicsLayer.loadStatus')
console.log(graphicsLayer.loadStatus)
console.log('---View Watch Updating Finish');
layer view =&gt; watch
view.whenLayerView(graphicsLayer).then(function (layerView) {
layerView.watch(&quot;updating&quot;, function (value) {
console.log('---Graphics Layer View Updating');
if (!value) {
console.log('---Graphics Layer View Updating ! value');
}
});
layerview-create
graphicsLayer.on(&quot;layerview-create&quot;, function (event) {
// The LayerView for the layer that emitted this event
graphicsLayerView = event.layerView;
console.log('---Graphics layer Layer View Create');
watchUtils.whenFalse(graphicsLayerView, &quot;updating&quot;, async () =&gt; {
console.log('---Watch: view graphicsLayerView Updating ' + graphicsLayer.loadStatus)
});
graphics layer =&gt; loaded
graphicsLayer.watch(&quot;loaded&quot;, () =&gt; {
console.log('---Graphics layer loaded');
graphics layer =&gt; load Status
watchUtils.watch(graphicsLayer, &quot;loadStatus&quot;, () =&gt; {
console.log('---Watch: graphicsLayer Load Status : ' + graphicsLayer.loadStatus)



{'source': 'StackExchangeDataset', 'subset': 'gis.stackexchange.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2022:00:04/07/22', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<arcgis-javascript-api>', 'Title': 'ESRI JS API 4x Graphics layer on load function', 'ViewCount': 74, 'id': 428309, 'user_AboutMe': None, 'user_AccountId': 4538069.0, 'user_DisplayName': 'user4906240', 'user_Reputation': 1037.0, 'user_Views': 58.0, 'user_id': 57135.0}}