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

2470
3
Jump to solution
08-18-2014 12:01 AM
lasinh
by
New Contributor III

<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/Map...");

          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/Map...");

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

                  graphic.setSymbol(symbol);

                  //Set the infoTemplate.

                  graphic.setInfoTemplate(infoTemplate);

                  //Add graphic to the map graphics layer.

                  map.graphics.add(graphic);

              }

          }

      });      

       </script>     

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

You title should be in the body of the message, it is far too long and not searchable.  Use appropriate tags to facilitate searching as well

View solution in original post

3 Replies
DanPatterson_Retired
MVP Emeritus

You title should be in the body of the message, it is far too long and not searchable.  Use appropriate tags to facilitate searching as well

lasinh
by
New Contributor III

it is not work. query is undefinded

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ia,

  In your code you never init a var called query. You have the proper require and the proper require alias for Query but you never var query in your code.

See line 24 on the code below.

<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 query, queryTask, infoTemplate, symbol;

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

          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/Map...");

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

                  graphic.setSymbol(symbol);

                  //Set the infoTemplate.

                  graphic.setInfoTemplate(infoTemplate);

                  //Add graphic to the map graphics layer.

                  map.graphics.add(graphic);

              }

          }

      });    

      </script>

0 Kudos