Feature Layer with sublayers

I have several layers I want to add to a map. Each layer has sublayers and an attribute table. When I was first practicing with adding layers, I made them all MapImageLayers so I could see the sublayers. Now I want to add popups that display the information in the attribute table. But when I made the layers all FeatureLayers, all of my sublayers disappeared! The FeatureLayer documentation doesn't mention children or sublayers, so I'm not sure how to get the sublayers to show back up in my LayerList widget. Help me ArcGISPros-wan-Kenobi, you're my only hope!

No there is not, so it is back to a MapImageLayer for you then. If you want the MapService to be one layer in the layer list with sublayers as children then you need to use MapImageLayer. So back to the question of your original intent/need. If you need to specify a popup for a sublayer of a MapImageLayer then you just assign the sublayer a specific popup.

// Overrides the drawing info on the layer with a custom renderervar citiesLayer = layer.sublayers.getItemAt(3);citiesLayer.popupTemplate =newPopupTemplate({ title:"Population in {NAME}", content:"As of 2010, the population in this area was <b>{POP2010:NumberFormat}</b>."+"As of 2013, the population here was <b>{POP2013:NumberFormat}</b>."+"Percent change is {POP2013:populationChange}"});

Thanks for reply Robert, it worked great. However, in my layerList widget, the FeatureLayer shows up as a separate layer. This makes sense, because I added it to the Map the same way I added all of the MapImageLayeres. I would like to replace the sublayer with the FeatureLayer, not make it seperate from its parent layer. Is there a way to do this?

No there is not, so it is back to a MapImageLayer for you then. If you want the MapService to be one layer in the layer list with sublayers as children then you need to use MapImageLayer. So back to the question of your original intent/need. If you need to specify a popup for a sublayer of a MapImageLayer then you just assign the sublayer a specific popup.

// Overrides the drawing info on the layer with a custom renderervar citiesLayer = layer.sublayers.getItemAt(3);citiesLayer.popupTemplate =newPopupTemplate({ title:"Population in {NAME}", content:"As of 2010, the population in this area was <b>{POP2010:NumberFormat}</b>."+"As of 2013, the population here was <b>{POP2013:NumberFormat}</b>."+"Percent change is {POP2013:populationChange}"});

Thanks Robert, this is exactly what I was looking for! This code makes a lot of sense.

Small problem, though: layer.sublayers comes back empty. This is what I have

var BREADCADLayer = landLayer.sublayers.getItemAt(40);

with landLayer being a MapImageLayer that i know has sublayers. After removing the getItemAt() function and putting landLayer.sublayers.join() in a console.log, I confirmed that the collection is empty. Am i missing something here?

edit: I don't specify the sublayers property of landLayer in its constructor, as I want every sublayer in the MapService to be included. The only thing specified in the landLayer constructor is url.

umm, nothing really. I know the layer is loading because I can access it in layerList widget and it has sublayers. I put your code snippit at the bottom of my script, but I don't know if that guarantees that snippit gets executed last

edit: I should put your code snippit in something like view.then(snippit), so it load after everything is loaded?

I also have this problem. While it makes sense there is a one-to-one layer mapping, is there an easy way to discover available layers in the MapServer, and dynamically add those layers to the map, rather than having to manually add layer 0, 1 and 2? I don't mind requesting layer list from the server, and then iterating them, adding them to group layer or directly to the map; I just don't know how to query the ArcGIS MapServer for available layers. Since I get the url from a configuration, I'd rather avoid having to specify configuration per layer.

Resolution: Using a dynamic layer behind the scenes, I can iterate the Layers collection to create FeatureLayer for the layers in the MapServer, adding them to the map, while discarding the dynamic layer.