samirgambhir

Setting map extent to a group of graphics

Discussion created by samirgambhir on Feb 22, 2011
Latest reply on Mar 11, 2011 by jjmiller1980
Hi,
I am running a query to select a number of polygons based on an intersecting polygon. The selected polygons are contiguous and are highlighted when the query is complete. I am trying to set the map extent to the extent of all these polygons combined together but have been unsuccessful. I have tried suggestions posted on these forums and using samples provided by ESRI but am still unable to get the map to zoom to this area. I have tried creating an array to push graphics inside it. I have also tried creating a polygon feature, a feature set and a graphicsLayer as a container to hold all the selected graphics, but it didn't work. I am using ArcGIS Server 9.3 with JavaScript API. Please help.
(Note: The code below has been extracted from a longer version. It might be missing some braces)

function findPolygonsInExtent(extent) {
      
  var graphics = map.graphics.graphics;     
  var attr =[];
  var items = [];
        var graphic;
  var len=0;
       
  for (var i=0, il=graphics.length; i<il; i++) {
          graphic = graphics[i];
          if (extent.intersects(graphic.geometry)) {
   len = len + 1;
   var results = [];
  
   graphic.setSymbol(highlightSymbol);
   var featureAttributes = graphic.attributes;
   for (att in featureAttributes) {
             var s = featureAttributes[att];
    results.push(s);
   }
  
   attr = results.slice(0,10);
   for(var j=0, jl=10; j<jl; j++)
   {
    items.push(attr[j]);
   }
  
    } //if
   
          else if (graphic.symbol == highlightSymbol) {
            graphic.setSymbol(symbol);
          }
   
        } //for
  map.setExtent(//some polygon feature//.geometry.getExtent());
}

Outcomes