Select to view content in your preferred language

How to ensure multiple LayerViews are ready

1652
1
Jump to solution
03-14-2021 08:26 PM
GaryB
by
Occasional Contributor

Hi,  I'm new to the JavaScript API and am trying to use client side layerviews.  If I am working with multiple feature layers and want to make sure all of them are ready to use, is there an alternative to this nested ugliness?

 

 

        view.whenLayerView(myFirstLayer).then(function (myFirstLayerView) {
          view.whenLayerView(mySecondLayer).then(function (mySecondLayerView) {
            view.whenLayerView(myThirdLayer).then(function (myThirdLayerView) {
              // now that I know all my layer views are ready I can do things with them
            })
          })
        })

 

 

 

I did see the following and was thinking it would be clearer to just to do this 3 times

 

 

var layerView = await view.whenLayerView(layer);

 

 

 

but got an error message that said "await is only valid in async functions and the top level bodies of modules".  I saw the following at the top but don't really understand when I have to use it since most samples don't use it.

 

 

require([...], function (...) {

(async () => {

 

 

 

Any help would be appreciated.

Thanks!

 

 

0 Kudos
1 Solution

Accepted Solutions
1 Reply
BlakeTerhune
MVP Regular Contributor