how to get the list of layers in a map (map service)

Discussion created by jsn on Sep 6, 2013
Latest reply on Sep 18, 2013 by jsn
Hi all

I customized this sample pointing "basemap" to one of my local map services that has several layers


The function getMapLayers  shows only one layer not all of them.

function getMapLayers() {
        for (var j = 0, jl = myMap.layerIds.length; j < jl; j++) {
            var currentLayer = myMap.getLayer(myMap.layerIds[j]);
            alert("id: " + currentLayer.id + ", visible: " + currentLayer.visible + ", opacity: " + currentLayer.opacity);

Is there any other sample that list all the layers in  map service and  adds them to a drop down box