AnsweredAssumed Answered

How do a returned layer number to my web service url?

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

I have the following code and the script evaluate which layer is Support. In this case it is one. I would like to assign that value through JavaScript as opposed to hard coding it. jsonValue does give me what I want, but I can't figure out how to assign the number to the supportLayerUrl:

 

 var jsonValue;
    
    // 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;


            }
        }
        return jsonValue;
    })


    function checkValue() {
        alert(jsonValue);
    }
    


    // app configuration  
    var 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: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/1" 


    };

 

 

I would like for my supportLayerUrl be something like this:

supportLayerUrl: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/" + jsonValue

 

But I get jsonValue not defined. Any ideas?

Outcomes