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:

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