cthue

QueryTask Help

Discussion created by cthue on Nov 20, 2012
Latest reply on Nov 21, 2012 by cthue
Hello
I have no experience with the JavaScript API (only the WebADF and Silverlight).
I am trying to teach myself, and decided to create a QueryTask based on this documentation( http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/intro_querytask.htm#webprint  )

I cannot get my results to display. Here is my html:


[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
<title> Map</title>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.6"></script>
<script type="text/javascript">

  function init() {
   map = new esri.Map("mapDiv");
   var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer");
   map.addLayer(layer);

   queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0");
 
   query = new esri.tasks.Query();
   query.returnGeometry = true;
   query.outFields = ["*"];

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

   symbol = new esri.symbol.SimpleMarkerSymbol();
   symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE);
   symbol.setSize(20); symbol.setColor(new dojo.Color([255, 255, 0, 0.5]));

  }

  function executeQueryTask(population) {
   query.where = "POP1990 > " + population;
   queryTask.execute(query, showResults);
  }

  function showResults(featureSet) {
   alert("show results");
   map.graphics.clear();
   var resultFeatures = featureSet.features;
  
   for (var i = 0, il = resultFeatures.length; i < il; i++) { 
    var graphic = resultFeatures[i];
    graphic.setSymbol(symbol);   
    graphic.setInfoTemplate(infoTemplate);  
    map.graphics.add(graphic);
   }
  }



  dojo.addOnLoad(init);
</script>
</head>
<body>
<br />
US city population greater than :
<input type="text" id="population" value="500000" />
<input type="button" value="Get Details" onclick="executeQueryTask(dojo.byId('population').value);" />
<div id="mapDiv" style="width: 600px; height: 600px; border: 1px solid #000;">
</div>
Click on a city once it's highlighted to get an InfoWindow.
</body>
</html>[/HTML]--
Any help is greatly appreciated!

Outcomes