AnsweredAssumed Answered

Get list of layers from map service - v3.6 API

Question asked by CityOfSurrey on Aug 26, 2013
Latest reply on Aug 26, 2013 by kenbuja
I am having trouble getting a list of layers from a map service automatically.  If I assign the get layer list function to a button, I have no problem.  Here is
require(["esri/map", "esri/geometry/Extent", "esri/layers/ArcGISTiledMapServiceLayer", "esri/layers/ArcGISDynamicMapServiceLayer" ,"dojo/domReady!"], function(Map, Extent, ArcGISTiledMapServiceLayer,ArcGISDynamicMapServiceLayer,LayerInfo) {  var map = new Map("map", {extent: new Extent({"xmin":506835.3785030904,"ymin":5439759.165184998,"xmax":515698.93789687584,"ymax":5450607.1035475405,"spatialReference":{"wkid":26910}})  });  var baseMap = new ArcGISTiledMapServiceLayer(""); allCityHighUse = new ArcGISDynamicMapServiceLayer(""); map.addLayer(baseMap, allCityHighUse);  });   alert(getlayerID ('Test Layer'));  function getlayerId(layerName) {               var layerInfos =  allCityHighUse.layerInfos;                 for (var i=0, il=layerInfos.length; i<il; i++) {             var templayerName = layerInfos[i].name;             var layerId = layerInfos[i].id;                            if (templayerName == layerName) {                 alert(layerId);               }             return layerId;          }    }  

Any idea why?  If I console.log (allCityHighUse), during runtime I see the layerInfos object is populated.