Select to view content in your preferred language

How zoom into selected feature (multiple features will get selected)

1106
1
12-21-2012 12:07 AM
SreenivasaRaoPigili
Frequent Contributor
Hi,
   I have exported my task results into a grid view. Now if I select any row from the gridview, i am able to zoom into that particular feature by using the ESRI provided link under 'Show find task results in a DataGrid '.
   Now I am planning to extend the provided code - in such a way that - if I selects multiple features from the grid view, then also we have to zoom into those features. For this I have modified the existing code in below ways.
1. Taken all the selected features and added into one featureset. But in the featureset we dont have extent property to set to mapextent.
2. Taken all the graphics into a graphics layer. Here also we dont have extent property to set to mapextent.

Please find the used code below.

      //Zoom to the parcel when the user clicks a row
      function onRowClickHandler(evt)
   {
        var items = grid.selection.getSelected();
        for(var i=0;i<items.length;i++)
        {
   var clickedTaxLotId = items.PARCELID;
   var selectedTaxLot;
  
   var countyLayer = new esri.layers.GraphicsLayer();
      var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([98,194,204]), 2), new dojo.Color([98,194,204,0.5]));
           
   var features= [];
   var featureSet = new esri.tasks.FeatureSet();
   dojo.forEach(map.graphics.graphics,function(graphic)
   {
    if((graphic.attributes) && graphic.attributes.PARCELID === clickedTaxLotId)
    {
     features.push(graphic);
     featureSet.features = features;

     //countyLayer.add(graphic.geometry, symbol);
     //map.setExtent(countyLayer);
     //selectedTaxLot = graphic;
     return;
    }
   });
   //var taxLotExtent = selectedTaxLot.geometry.getExtent();
            //map.setExtent(taxLotExtent);
   map.setExtent(featureSet.Extent);
        }
      }



Can anyone help in this regards. Thanks in advance.
0 Kudos
1 Reply
RahulMetangale1
Frequent Contributor
You can use esri.graphicsExtent(graphics) method to get the extent of all graphics. And then set map extent to the extent returned.
here is the API reference for additional details:
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/namespace_esri.htm#esr...
0 Kudos