AnsweredAssumed Answered

Why can't I assign a layer to a value?

Question asked by csergent08 Champion on May 13, 2015
Latest reply on May 14, 2015 by csergent08

I am trying to loop through layers and this block of code works:

 var jsonValue, signUrl, supportUrl;
    var restEndPoint = "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/";
    var config;
    // Get the id of a layer
    var requestHandle = esriRequest({
        url: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/",
        content: {
            f: 'json'
        },
        handleAs: "json"
    });


    requestHandle.then(function (lyrJSON, io) {
        for (var i = 0; i < lyrJSON.layers.length; i++) {
            if (lyrJSON.layers[i].name = "Support") {
                jsonValue = lyrJSON.layers[i].id;
                supportUrl = restEndPoint + jsonValue;
            }
            
        }




        // app configuration  
        config = {






            mapOptions: {
                showAttribution: false,
                sliderStyle: "small",
                extent: initialExtent,
                logo: false,
                sliderPosition: "bottom-right"
            },


            signLayerUrl: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0",


            supportLayerUrl: supportUrl


        };
        initMap();
        
    })

 

 

But when I try to add the following code, I can't assign the value to signLayerUrl. I even tried to change i to t for the second if statement:

 

 var signValue, signUrl, supportValue, supportUrl;
    var restEndPoint = "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/";
    var config;
    // Get the id of a layer
    var requestHandle = esriRequest({
        url: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/",
        content: {
            f: 'json'
        },
        handleAs: "json"
    });


    requestHandle.then(function (lyrJSON, io) {
        for (var i = 0; i < lyrJSON.layers.length; i++) {
            if (lyrJSON.layers[i].name = "Support") {
                supportValue = lyrJSON.layers[i].id;
                supportUrl = restEndPoint + supportValue;
            }


            if (lyrJSON.layers[i].name = "Sign") {
                signValue = lyrJSON.layers[i].id;
                signUrl = restEndPoint + signValue;
            }
            
        }




        // app configuration  
        config = {






            mapOptions: {
                showAttribution: false,
                sliderStyle: "small",
                extent: initialExtent,
                logo: false,
                sliderPosition: "bottom-right"
            },


            signLayerUrl: signUrl,


            supportLayerUrl: supportUrl


        };
        initMap();
        
    })

Outcomes