ngalford

Scope or hoisting issue with layer creation

Discussion created by ngalford on Jun 10, 2013
I'm building in reusability to support easier layer addition and code support for any issues in the future.  I think I'm having a scope problem, my goal is to create layers dynamically and another other map building processes will leverage the dynamic build process or subsequent layers for usage.

EDIT: moved to a single sheet for single solution, I'll work on porting to another code format later.  Now the code breaks on initilization of the new esri tiled layer.:

var tester = addTileLyr('http://esoc1.nscorp.com/ArcGISProduction/rest/services/EGIS/ENG_TRACK/MapServer/',true,'Track','checked','img/ui/track16x16.png', tester);

//

var addTileLyr = function (url, add2Map, lyrNm, setChk, img, place) {
        setTiledLayer(url, add2Map, place);
        getLyrSuccess(tuID, lyrNm, setChk, img);
      };

//

var setTiledLayer = function(URL, addlyr, place) {
       place = new esri.layers.ArcGISTiledMapServiceLayer(URL);
       /*if (addlyr !== false) {
         //map.addLayer(tuID);
       }*/
       return tuID;
      };

//

var lyrSuccess = function (lyrVar, lyrName, chkSt, img) {
      dojo.connect(lyrVar, 'onLoad', function (layer) {
          if (layer) {
            var sldID =  makeid();
            $('#layersList').append('<li id = ' + esriLyrID + ' class = "Layer"><input type="checkbox" ' + chkSt + ' onClick = "chkBox(' + "'" + lyrVar.id + "'" + ')"/><span class = "toggle cBicon"><img alt = "" style=" display: block; margin: 5px 0;" src=' + img + '></img><span class="toggle cBittle" text = ' + img + '></span></span><span class="toggle cBtitle">' + lyrName + '</span><span id = ' + sldID + ' class="sliderO"></span></li>');
            $('#' + sldID).slider({
                min: 0,
                max: 1,
                value: 1,
                step: 0.10,
                change: function (event, ui) {
                    lyrVar.setOpacity(ui.value);
                }
            });
            //map.addLayer(layer);
          }
      });
    }; 

Outcomes