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:
@ReneRubalcava3 in another posting you suggested using the method fromArcGISServerUrl but does it has limitations on sublayers?
Solved! Go to Solution.
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
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