Select to view content in your preferred language

Check if feature layer can be added before adding

406
2
Jump to solution
02-14-2023 01:41 AM
Aeseir
by
Occasional Contributor II

Is there any way to determine if a feature layer can be accessed by the map before adding it?

 

In cases where a layer is a protected resource, I don't want it sitting in the layerlist with a warning that it is not accessable.

0 Kudos
1 Solution

Accepted Solutions
Aeseir
by
Occasional Contributor II

close @Christer , no need for whenOnce().

It ended up being along the lines of:

 

 

 

try {
   await layer.load();

   // execute rest of code
} catch (e) {
// manage exception
}

 

 

View solution in original post

0 Kudos
2 Replies
Christer
New Contributor II

Hi, you can manually try load the layer before adding it to the map. if im not mistaken. 

Sample: 

 

import { whenOnce } from '@arcgis/core/core/reactiveUtils';

myLayer = new FeatureLayer(..)
whenOnce(() => myLayer.loaded == true).then(() => {
      console.log('All good');
      view.map.add(myLayer);
    });
myLayer.load();

 

 

0 Kudos
Aeseir
by
Occasional Contributor II

close @Christer , no need for whenOnce().

It ended up being along the lines of:

 

 

 

try {
   await layer.load();

   // execute rest of code
} catch (e) {
// manage exception
}

 

 

0 Kudos