Zoom to graphic

4485
2
12-13-2011 06:26 AM
MikeOnzay
Occasional Contributor III
I still don't understand how to zoom to the extent of a feature(graphic). The help/samples are not quite basic enough. I can see my graphic but I cannot zoom to it. I also want to use expand.

function showResults(featureSet){
 map.graphics.clear();
        var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID).setColor(new dojo.Color([255, 0, 0, 0.5])); 
        //Loop through features in the featureSet and add them to the map.
        for (var i=0, il=featureSet.features.length; i<il; i++) {
 //Get the current feature from the featureSet.
        //Feature is a graphic
            var graphic = featureSet.features;
            graphic.setSymbol(symbol);
     graphic.geometry.getExtent().expand(0.5); //my attempt
   
            //Add graphic to the map graphics layer.
            map.graphics.add(graphic);
          }
  }
0 Kudos
2 Replies
derekswingley1
Frequent Contributor
If you want to get the extent for all of your features, there are a couple of options:
-use esri.graphicsExtent() 
-build an extent using esri.geometry.Extent.union() to manually build an extent from your features

Once you have an extent, pass it to map.setExtent() to zoom to your features.
0 Kudos
MikeOnzay
Occasional Contributor III
Got it. Finally. Thanks.
0 Kudos