Select to view content in your preferred language

when is symbology visible and MapImageLayer ready

552
4
Jump to solution
09-13-2022 02:05 PM
GregoryBologna
Frequent Contributor

I am looking for a way to know when MapImageLayer symbology is visible and there's nothing pending. Adding a watch for reactiveUtils does show me that the MapImageLayer is loaded, but the symbology is still not visible for up to 5 seconds. (the view.when is also hit). I am trying to disable some widget buttons until after the map and symbology is fully loaded with nothing pending before I enable the buttons. I am also updating a few layers in listItemCreatedFunction and have a watch reactiveUtils there too, but still not helping. I'm thinking about just adding a 5 second timer if there's nothing else available.

🙄At this point my watch indicates the MapImageLayer is loaded, but there's no symbology yet.

GregoryBologna_0-1663101875373.png

😊At this point I can enable my widget buttons

GregoryBologna_1-1663101894750.png

 

        const mapLayerAndLabels = new MapImageLayer({
            url: mapLayerAndLabelsUrl,
            legendEnabled: true,
            visible: true,
            title: 'Map Layers & Labels',
        });
        map.add(mapLayerAndLabels);

 

This is in listItemCreatedFunction

 

        reactiveUtils.whenOnce(
            () => mapLayerAndLabels.loaded)
            .then(() => {
                console.log(`mapLayerAndLabels is loaded.`);
            });

 

 

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Honored Contributor

You can try watching the layerView updating property.

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html#whenOnce

 

view.when(async () => {
	const layerView = await view.whenLayerView(layer);
	await whenOnce(
		() => !layerView.updating
	);
	console.log("map image layer done drawing");
});

 

 

You could wait for view.updating too, it's based off the child layerviews updating property. 

View solution in original post

0 Kudos
4 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

You may find this blog by @ReneRubalcava useful: https://odoe.net/blog/when-are-layers-done. Use the reactiveUtils instead of watchUtils. 

 

0 Kudos
GregoryBologna
Frequent Contributor

I am.

0 Kudos
ReneRubalcava
Honored Contributor

You can try watching the layerView updating property.

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html#whenOnce

 

view.when(async () => {
	const layerView = await view.whenLayerView(layer);
	await whenOnce(
		() => !layerView.updating
	);
	console.log("map image layer done drawing");
});

 

 

You could wait for view.updating too, it's based off the child layerviews updating property. 

0 Kudos
GregoryBologna
Frequent Contributor

Thank you, Rene. Your example helped. I put this together to show a loader during updating.

        view.watch('updating', async (state) => {
            let elm = document.querySelector('#pao-modal-loading');
            if (elmelm.open = state;
        });
0 Kudos