QueryTask Help

744
2
11-20-2012 11:30 AM
CurtThue
New Contributor III
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/Map...");
   map.addLayer(layer);

   queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/Map...");
 
   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;
    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!
0 Kudos
2 Replies
__Rich_
Occasional Contributor III
I've just tried the code that you posted - works fine for me???

You're missing some CSS but that's not affecting the functionality.

Also, you're using an old version (v2.6) of the API, any particular reason why you aren't using the latest version? (v3.2)
0 Kudos
CurtThue
New Contributor III
I've just tried the code that you posted - works fine for me???

You're missing some CSS but that's not affecting the functionality.

Also, you're using an old version (v2.6) of the API, any particular reason why you aren't using the latest version? (v3.2)


Yes, it is working now! Maybe there was an issue with the service or something wrong locally. Thanks for looking.
0 Kudos