Select to view content in your preferred language

Zoom to DataGrid results not working

1853
4
10-24-2011 02:09 AM
EdSaunders
Regular Contributor
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;
  }
});
}
0 Kudos
4 Replies
HemingZhu
Frequent Contributor
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;
  }
});
}


Change strict comparison === to == and try again.
0 Kudos
EdSaunders
Regular Contributor
Heming, thanks for your response.  No luck without the strict comparison unfortunately. Not sure what's going on but I'll keep looking and report back.

Thanks for your input.

Ed
0 Kudos
EdSaunders
Regular Contributor
Hi all,

Just been looking at the network traffic and it seems the zoom is failing because the following request is being generated from my code:


http://<server>/ArcGIS/rest/services/SLR/CadastreRoad/MapServer/0/query?
f=json
&returnGeometry=true
&spatialRel=esriSpatialRelIntersects
&objectIds=2401863
&outFields=PLANNUMBER%2CLOTNUMBER%2COBJECTID%2CSECTIONNUMBER%2CclassSubtype
&outSR=102113
&callback=dojo.io.script.jsonp_dojoIoScript10._jsonpCallback

The problem is that %2classSubtype is being added to the end of the request for some reason.  Does anyone know why this is happening??  Where is that coming from? 

Thanks for the help.

Ed
0 Kudos
HemingZhu
Frequent Contributor
Hi all,

Just been looking at the network traffic and it seems the zoom is failing because the following request is being generated from my code:


http://<server>/ArcGIS/rest/services/SLR/CadastreRoad/MapServer/0/query?
f=json
&returnGeometry=true
&spatialRel=esriSpatialRelIntersects
&objectIds=2401863
&outFields=PLANNUMBER%2CLOTNUMBER%2COBJECTID%2CSECTIONNUMBER%2CclassSubtype
&outSR=102113
&callback=dojo.io.script.jsonp_dojoIoScript10._jsonpCallback

The problem is that %2classSubtype is being added to the end of the request for some reason.  Does anyone know why this is happening??  Where is that coming from? 

Thanks for the help.

Ed


Another thought is your dojo.some. It is use to validate the exist of a value rather then loop through each query result. Try dojo.forEach.
0 Kudos