agreig2007

select points in a graphic when there is a time slider

Discussion created by agreig2007 on Jun 8, 2011
Latest reply on Jun 9, 2011 by agreig2007
My code allows a user to draw a polygon to select some points.  Initially everything works fine.  However if I move the time slider to a different year and draw a polygon only some or none of the enclosed points are selected.  Here is some of the relevant code.
Thanks.

      function initToolbar(map) {
        tb = new esri.toolbars.Draw(globals.map);
        dojo.connect(tb, "onDrawEnd", addGraphic);
      }

      function addGraphic(poly) {
        var symbol = tb.fillSymbol;
        globals.map.graphics.add(new esri.Graphic(poly, symbol));

        var queryTask = new esri.tasks.QueryTask("http://..../MapServer/0");
        var query = new esri.tasks.Query();
        query.where = "SPECIES_CODE = " + globals.speciesID +" and YEAR = " + globals.year;
        query.outSpatialReference = {wkid:102100};
        query.timeExtent = globals.map.timeExtent;
        query.returnGeometry = true;
        query.outFields = ["YEAR","SPECIES_CODE"];
        queryTask.execute(query, addPointsToMap);
      }

      //add points to map and set their symbology
      function addPointsToMap(featureSet) {
        var i = globals.map.graphics.graphics.length - 1;
        dojo.forEach(featureSet.features,function(feature){
          if (globals.map.graphics.graphics[i].geometry.contains(feature.geometry)) {
            globals.map.graphics.add(feature.setSymbol(new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([255,0,0]))));
          }
        });
     }

      function timeSliderChanged(timeExtent)
      { 
         globals.year = timeExtent.endTime.getUTCFullYear();
         globals.map.graphics.clear()
         showMapInfo();
      }

Outcomes