AnsweredAssumed Answered

query is undefined  I built this code from this example page here on how to use a querytask. I changed the fieldname being used in the where clause because the field in the example doesn't exist. I tested my

Question asked by sinharcgis on Aug 18, 2014
Latest reply on Aug 18, 2014 by rscheitlin

<script type="text/javascript">

        require([

      "esri/map",

      "esri/layers/ArcGISDynamicMapServiceLayer",

     "dojo/dom",

       "dojo/on",

      "esri/tasks/QueryTask",

      "esri/tasks/query",

      "esri/symbols/SimpleMarkerSymbol",

      "esri/InfoTemplate",

      "dojo/_base/Color",

      "dojo/domReady!"],

       function (Map,

        ArcGISDynamicMapServiceLayer,

         dom,

          on,

           QueryTask,

           Query,

           SimpleMarkerSymbol,

            InfoTemplate,

             Color,

             domReady) {

          map = new Map("map");

          var layer = new ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer");

          map.addLayer(layer);

          var pop = dojo.byId('search-text').value;

          on(dojo.byId('search-button'), "click", executeQueryTask(pop));

 

 

          //initialize query task

          queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0");

          //initialize query

          query = new esri.tasks.Query();

          query.returnGeometry = true;

          query.outFields = ["CITY_NAME", "STATE_NAME", "POP1990"];

 

 

          //initialize InfoTemplate

          infoTemplate = new InfoTemplate("${CITY_NAME}", "Name : ${CITY_NAME}<br/> State : ${STATE_NAME}<br />Population : ${POP1990}");

 

 

          //create symbol for selected features

          symbol = new SimpleMarkerSymbol();

          symbol.setStyle(SimpleMarkerSymbol.STYLE_SQUARE);

          symbol.setSize(10);

          symbol.setColor(new Color([255, 255, 0, 0.5]));

 

 

 

 

          function executeQueryTask(population) {

 

 

              //set query based on what user typed in for population;

! !

              query.where = "POP1990 >"+ population;

 

 

              //execute query

              queryTask.execute(query, showResults);

          }

          function showResults(featureSet) {

              //remove all graphics on the maps graphics layer

              map.graphics.clear();

 

 

              //Performance enhancer - assign featureSet array to a single variable.

              var resultFeatures = featureSet.features;

 

 

              //Loop through each feature returned

              for (var i = 0, il = resultFeatures.length; i < il; i++) {

                  //Get the current feature from the featureSet.

                  //Feature is a graphic

                  var graphic = resultFeatures[i];

                  graphic.setSymbol(symbol);

 

 

                  //Set the infoTemplate.

                  graphic.setInfoTemplate(infoTemplate);

 

 

                  //Add graphic to the map graphics layer.

                  map.graphics.add(graphic);

              }

          }

      });      

       </script>     

Outcomes