Trouble with InfoWindow on mouse hover

Discussion created by bgfield on May 30, 2012
I'm a total newbie when it comes to javascript, so please bear with my ignorance!

I've been trying to recreate the Load query results, show on hover example in the help section, and I've been running into some trouble.  First off, why do I need to do a query task, then add the feature set to the map as a graphic, in order to get an info window on mouse hover?  I'm able to get an info window with a click pretty simply, without having to use a query at all.

Secondly, in the example code, what if I wanted the query to produce EVERY county, and not just those in South Carolina?  I ask because for the layers I'll be working with, I do want to be able to mouse over every feature and get an info window.  For example, look at my code below:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <title>QueryTask with geometry, results as an InfoWindow onHover</title>
    <link rel="stylesheet" type="text/css" href="">
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" language="Javascript">

      function init() {
        //create map
        var map = new esri.Map("mapDiv");
        //listen for when map is loaded and then add query functionality
        dojo.connect(map, "onLoad", initFunctionality);

        //create and add new layer
        var layer = new esri.layers.ArcGISTiledMapServiceLayer("");

      function initFunctionality(map) {
        //build query task
        var queryTask = new esri.tasks.QueryTask("");

        //build query filter
        var query = new esri.tasks.Query();
        query.returnGeometry = true;
        query.outFields = ["BARNAME", "OTHERNAMES", "YATESBRS"];

        var infoTemplate = new esri.InfoTemplate();
        infoTemplate.setTitle("Historic Oyster Bar");
        infoTemplate.setContent("<b>Name</b>: ${BARNAME}<br/>"
                             + "<b>Other Names</b>: ${OTHERNAMES}<br/>");


        //Can listen for onComplete event to process results or can use the callback option in the queryTask.execute method.
        dojo.connect(queryTask, "onComplete", function(featureSet) {
          var highlightSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 3), new dojo.Color([125,125,125,0.35]));
          //var highlightSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 3);
          var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([168, 112, 0, 255]), 1),new dojo.Color([255,255,255,0.0]));

          var countiesGraphicsLayer = new esri.layers.GraphicsLayer();
          //QueryTask returns a featureSet.  Loop through features in the featureSet and add them to the map.
          for (var i=0, il=featureSet.features.length; i<il; i++) {
            //Get the current feature from the featureSet.
            //Feature is a graphic
            var graphic = featureSet.features;

            //Add graphic to the counties graphics layer.
          //listen for when the onMouseOver event fires on the countiesGraphicsLayer
          //when fired, create a new graphic with the geometry from the event.graphic and add it to the maps graphics layer
          dojo.connect(countiesGraphicsLayer, "onMouseOver", function(evt) {
  ;  //use the maps graphics layer as the highlight layer
            var content = evt.graphic.getContent();
            var title = evt.graphic.getTitle();
            var highlightGraphic = new esri.Graphic(evt.graphic.geometry,highlightSymbol);

          //listen for when onMouseOut event is fired and then clear the highlight graphic
          //and hide the info window
          dojo.connect(, "onMouseOut", function(evt) {

  <body class="tundra">
   <div id="mapDiv" style="width:900px; height:600px; border:1px solid #000;"></div>

When I run this, I expect every feature in the queried layer to be produced on the map; however, none of them are!  I determined that I needed to add a filter, such as [i]"query.where = "YATESBRS = 'Y'";.  This would display every feature containing a value of "Y" in the YATESBRS field; but I want every feature to be displayed.  How can I accomplish this?