Select to view content in your preferred language

Missing sublayers

391
1
Jump to solution
03-01-2023 10:19 AM
LefterisKoumis
Frequent Contributor

UPDATE: 

I modified the script and it captures all sublayers. But is there an easier and more direct way of doing it?

Updated script:

  Layer.fromArcGISServerUrl({
    url: "https://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/Urban/MapServer ",
  }).then(function (layer) {
    layer.when(() => {
      layer.sublayers.map((sublayer) => {
        const id = sublayer.id;
        console.log(id);
        if (sublayer.sublayers) {
          sublayer.sublayers.map((sublayer1) => {
            const id = sublayer1.id;
            console.log(id);
          });
        }
      });
    });
  });

________________________________________________________________________________

Original Post

I am trying to get access to all sublayers. However, the sublayers  of a sublayer seems to be skipped of. 

For example, for this REST service at:

https://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/Urban/MapServer 

sublayers 2  and 5 are skipped off when I run this script. It seems that sublayers of a sublayer are not detected.

 

 

 

Layer.fromArcGISServerUrl({
    url: "https://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/Urban/MapServer ",
  }).then(function (layer) {  
    layer.when(() => {
      layer.sublayers.map((sublayer) => {
        const id = sublayer.id;
        console.log(id);
      });
    });
  });

 

 

 

Output:

LefterisKoumis_0-1677694664763.png

 

@ReneRubalcava3 in another posting you suggested using the  method fromArcGISServerUrl but does it has limitations on sublayers?

 

 

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Honored Contributor

You can try using layer.loadAll() and it should load all sublayers and child sublayers for you.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-MapImageLayer.html#loadAll

 

Oh, and Sublayers is a Collection, so you can flatten it after.

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

View solution in original post

1 Reply
ReneRubalcava
Honored Contributor

You can try using layer.loadAll() and it should load all sublayers and child sublayers for you.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-MapImageLayer.html#loadAll

 

Oh, and Sublayers is a Collection, so you can flatten it after.

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