Setting a zoom level based on the size or shape of a feature

Discussion created by monzay on Dec 14, 2011
Latest reply on Dec 15, 2011 by monzay
I want to display a feature on my map to provide better context within the surrounding area than usinng setExtent or setExtent().expand().

In this example, Display Find Task in Grid, the map displays each parcel at an extent that I think is too close for the viewer to see it within the context of the surrounding area. This is especially true for really small parcels. For larger parcels you get a slightly better view. Even so, in many cases, part of the boundary is blocked by the window.

Would it be possible to evaluate the size/shape/area of each feature and then set a zoom level or extent that would provide a better view of the surrounding area? In other words, not be too close or too far away?

I saw esri.geometry.geodesicAreas(polygons, areaUnit) and also saw I would probably need to use esri.geometry.webMercatorToGeographic(geometry) first.

I tried adding a couple of lines in this function from the sample. I did not get any errors but I also did not see any numbers return in my console. Am I using this correctly? Overall, am I on the right track?

      function onRowClickHandler(evt){
        var clickedTaxLotId = grid.getItem(evt.rowIndex).PARCELID;
        var selectedTaxLot;

          if((graphic.attributes) && graphic.attributes.PARCELID === clickedTaxLotId){
            selectedTaxLot = graphic;
  var x = esri.geometry.webMercatorToGeographic(selectedTaxLot.graphic); 
  var areas = esri.geometry.geodesicAreas(x, esri.Units.ACRES);
        var taxLotExtent = selectedTaxLot.geometry.getExtent();