bundarrabandito

Zoom to DataGrid results not working

Discussion created by bundarrabandito on Oct 24, 2011
Latest reply on Oct 25, 2011 by hzhu
Hi all,

This is probably an easy one but I can't figure it out...I'm sending query tasks results to a graphics layers with attributes.  I'm also populating a DataGrid with the results and then trying to zoom to a record when the user clicks on a row.  Except the zoom function doesn't work and I get the following error:

'graphic.attributes is undefined' at the following line in the zoomRow function:

if (graphic.attributes.OBJECTID.toString() === id) {

It seems that when the zoom function tries to access the graphics layer attributes, it can't find OBJECTID.  Below is the code for the query task.  Any help is VERY much appreciated!

Thanks,

Ed

function executeTask() {

var planNumber = dijit.byId('planNumber').value;
var lotNumber = dijit.byId('lotNumber').value;
var queryTask = new esri.tasks.QueryTask("http://<server>/ArcGIS/rest/services/SLR/CadastreRoad/MapServer/0");
var query = new esri.tasks.Query();
query.returnGeometry=true;
query.outFields = ["PLANNUMBER","LOTNUMBER","OBJECTID","SECTIONNUMBER"];
query.where = "PLANNUMBER='" + planNumber + "' AND LOTNUMBER='" + lotNumber + "'";
dojo.connect(queryTask,"onComplete", function(featureSet) {
  //build an array of attributes
  var items = dojo.map(featureSet.features, function(feature) {
   return feature.attributes;
  });
  var data = {
   identifier:"OBJECTID",
   items:items
  };
  store = new dojo.data.ItemFileReadStore({
   data:data
  });
  grid.setStore(store);
  grid.setSortIndex(1,"true"); //sort on the state name
  dojo.forEach (featureSet.features, function(feature) {
   map.graphics.add(feature);
  });
});
queryTask.execute(query);
}

function makeZoomButton(id) {

var zBtn = "<div dojoType='dijit.form.Button'><img src='images/zoom.png'";
zBtn = zBtn + " width='18' height='18'";
zBtn = zBtn + " onClick=\"zoomRow('"+id+"')\"></div>";
return zBtn;
}

function zoomRow(id) {

selectionLayer.clear();
dojo.some(map.graphics.graphics, function(graphic) {
  if (graphic.attributes.OBJECTID.toString() === id) {
   var selectedState = new esri.Graphic(graphic.geometry).setAttributes(
   graphic.attributes);
   selectionLayer.add(selectedState);
   var stateExtent = selectedState.geometry.getExtent().expand(5.0);
   map.setExtent(stateExtent);
   return true;
  }
});
}

Outcomes