AnsweredAssumed Answered

How to get all layers and sublayers of a Map in a flat collection

Question asked by Eletrosul on May 16, 2017
Latest reply on May 16, 2017 by TSolow-esristaff

I have a WebMap : WebMap | API Reference | ArcGIS API for JavaScript 4.3 


Layers in a WebMap are MapImageLayers that contain SubLayers.


In the WebMap API Reference, it mentions that WebMap.allLayers it's a flat collection of all layers, but not sublayers.


My question is, how can I have a collection of all "effective" layers and sublayers, and not group layers.


Because how am I supposed to find a layer by title/url that is specified in a configuration file in my map?


This is what I've tried :


        webmap = new WebMap({
          portalItem: { // autocasts as new PortalItem()
            id: "5bc9a1fdb2ea4d359f2404cd51a64605"
            console.log('Map allLayers :', instance.allLayers.toJSON()); //No sublayers
            return new MapView({
                map: instance,
                container: "map"
            console.log(' allLayers :',; //Same thing as above
            console.log('View allLayerViews :',instance.allLayerViews.toJSON()); //Empty