samirgambhir

Selecting polygons intersecting with another polygon

Discussion created by samirgambhir on Jan 23, 2011
Latest reply on Jun 17, 2011 by hzhu
Hi,
I have been trying to make this code work for sometime which should have taken me less time than I have spent on it so far. My code looks up a zip code file, selects a zipcode based on user selection. Once selected, it highlights the selected zipcode (mycode works till this point very well) and runs a query on another file to select all census tracts that intersect with the selected zipcode boundary. My code stops short of selecting tracts based on zipcode selection. Any help to resolve this will be great! Here is my code:

function QueryByZip(Zip_ID){
map.graphic.clear();
     dijit.byId('progress').show();
  queryTask= new esri.tasks.QueryTask("http://128.146.162.230/arcgis/rest/services/KC_zipcodes/MapServer/2");
  query = new esri.tasks.Query();
  query.where = "ZIP = '" + Zip_ID + "'";
  query.returnGeometry = true;
  query.outFields = ["ZIP"];
  queryTask.execute(query);
  dojo.connect(queryTask, "onComplete", zoomToZip);
}

function zoomToZip(featureSet){
var features = featureSet.features;
var zipGraphic;
  for (var i=0, il=features.length; i<il; i++) {
     zipGraphic = new esri.Graphic(features[i]);
          map.graphics.add(zipGraphic.setSymbol(zipSymbol));
    }
  queryTask2= new esri.tasks.QueryTask("http://128.146.162.230/arcgis/rest/services/KingCountyAllOverlaysForQueryNew/MapServer/0");
  query2 = new esri.tasks.Query();
  query2.geometry = zipGraphic.geometry;
  query2.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
  query2.returnGeometry = true;
  queryTask2.execute(query2);
  dojo.connect(queryTask2, "onComplete", selectTracts);
}

function selectTracts(featureSet) {
var featureTracts = featureSet.features;
var tractGraphic;
       for (var i=0, il=featureTracts.length; i<il; i++) {
     tractGraphic = new esri.Graphic(featureTracts[i]);
        map.graphics.add(tractGraphic.setSymbol(highlightSymbol));
    }
    map.setExtent(tractGraphic.geometry.getExtent());
}

Outcomes