I am attempting to show a loading indicator in my React application while the LayerList is loading. Once loaded and ready to be displayed I want to show the LayerList. However, it seems the LayerList.viewModel.state property is changed to "ready" before the LayerList is ready to be displayed.
I can confirm this with this scenario.
- Set up an application with the following code
const map = new WebMap({
portalItem: {
id: "ef2644781da844648e8bb30ab52a02bc",
},
});
const view = new MapView({
container: "viewDiv",
map: map,
});
const layerList = new LayerList({
view,
visibilityAppearance: "checkbox",
});
reactiveUtils.watch(
() => layerList.viewModel.state,
(newState, oldState) => console.log(`OldState: ${oldState} NewState: ${newState}`)
);
view.ui.add(layerList, "top-right");
- In the browser, filter Network so you only see request to "/assets/panel/t9n/messages_en.json"
- Run the application
- Note that "ready" is established before the that aforementioned asset is loaded
- Now block access to that resource
- Run the application
- Note that the LayerList will not load at all
It appears LayerList depends on (and other assets) to render. However, if this asset is not loaded the LayerList will not render at all. On slow networks such as mine, this can be a substantial (many second delay) resulting in my loading indicator (not shown in the code about) disappearing before the LayerList is ready, leaving an unsightly blank area until all the assets load.
Is there another way to determine when the LayerList is truly ready to be rendered?