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.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(); }
query.where = "SPECIES_CODE = " + globals.speciesID +" and YEAR = " + globals.year; query.timeExtent = globals.map.timeExtent;
function timeSliderChanged(timeExtent) { globals.year = timeExtent.endTime.getUTCFullYear(); }
Are you sure you need to store the year in a variable, and use this in the query.where statement? If the layer is time-aware, then the query's time extent (query.timeExtent = map.timeExtent) should take care of this for you.
Can you put a break-point inside the timeSliderChanged function, and verify that globals.year is being set correctly? They put another break-point inside the query and ensure that query.where is correct?
Steve, Thanks you put me on the right track. I had been convinced that the problem was with geometry.contains statement whereas the query return was faulty. The query itself was fine. The solution lay in changing a parameter during the service creation. I increased the limit on the number of records returned and problem solved. Thanks for your help, agreig