AnsweredAssumed Answered

QueryTask onComplete with Parameters

Question asked by David.Kucharski@23 on Oct 11, 2019
Latest reply on Oct 14, 2019 by belan-esristaff

I have a function that loops through a list of geographies. Each Geography has a specific color assigned to it. I want to call a QueryTask within a loop for each geography. This will then call another function (oncomplete) that will take the result, assign a color to it and add it to a layer. 

 

The issue is how can I pass the specific color I need the geography to be? The oncomplete function only takes the result set of the querytask. I try to set variables but since it is async, multiple querytasks fire at the same time and the color is not specific to the geography anymore. 

 

Function with the QueryTask

function OnVersionSuccess(response, userContext, methodName) {
            var temp = response.toString();

            colorOverlayLyr.removeAll();
            var resultArray = temp.split("|");

            for (var i = 0; i < resultArray.length; i++) {

                     var values = resultArray[i].split("~");

                     params.where = "ID_ IN ('" + values[0] + "')";    //a single geography
                     glRed = values[1];                                              //red,green.blue values for the color the geography overlay
                     glGreen = values[2];
                     glBlue = values[3];
                     // executes the query and calls getResults() once the promise is resolved
                     // promiseRejected() is called if the promise is rejected
                     qTask.execute(params)
                              .then(getVersionResults)
                              .catch(promiseRejected);
            }

            document.body.style.cursor = "default";
}

 

Function called onComplete: getVersionResults

function getVersionResults(response) {
                  // Loop through each of the results and assign a symbol and PopupTemplate
                  // to each so they may be visualized on the map
                  var peakResults = arrayUtils.map(response.features, function (
                                                                                 feature) {

                           feature.symbol = {
                              type: "simple-fill", // autocasts as new PointSymbol3D()
                              color: {
                                    r: glRed,
                                    g: glGreen,
                                    b: glBlue,
                                    a: 0.5
                                 },
                           style: "solid",
                           opacity: 0.2,
                           outline: { color: "black", width: 1 }
                              };

                  return feature;
                });

               colorOverlayLyr.addMany(peakResults);
}

Outcomes