QueryTask onComplete with Parameters

10-11-2019 02:10 PM
New Contributor II

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();

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

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

                     var values = resultArray.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

            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;


0 Kudos
1 Reply
Esri Contributor

If the geographies have a unique id you could create a dict to use when assigning colors

const dict = {
  id1: "color1",
  id2: "color2",
0 Kudos