Select to view content in your preferred language

ZoomTo Object in DataGrid Table

674
2
11-12-2010 10:31 AM
DidumAbraham
Deactivated User
I have an item in a datagrid table and I'm trying to use the itemClick event to zoom-in to each item on the map when clicked on the item. Has anyone worked similar proejct?

var myGra:ArrayCollection = myGraphicsLayer.myGra as ArrayCollection;
          var myGraExt:Extent = GraphicUtil.getGraphicsExtent(myGra.toArray());
          myMap.extent = myGraExt.expand(2.4);


However, this approach from esri samples zooms to all features instead of each individual item.
Tags (2)
0 Kudos
2 Replies
GadyPitaru
Emerging Contributor
I'm assuming that you are populating the DataGrid.dataProvider with QueryTask.executeLastResult.attributes and the features on the map are on a GraphicsLayer with the graphicProvider populated by QueryTask.executeLastResult.features. If that's the case, in the itemClick handler you can loop through and try to match some unique ID in the features with a unique ID of the attribute clicked on in the DataGrid, like this:

for each(var feature:Graphic in queryTask.executeLastResult.features)
{
 if(feature.attributes.ID== event.itemRenderer.data.ID)
 {
  myMap.extent = feature.geometry.extent;
 }
}
0 Kudos
DidumAbraham
Deactivated User
I'm not using QueryTask.executeLastResult.attributes, but I am using findTask. Here is sample code...
private function doFind():void {
 var FindParams:FindParameters = new FindParameters();     FindParams.contains = true;
 FindParams.layerIds = [0];
 FindParams.outSpatialReference = myMap.spatialReference;
 FindParams.returnGeometry = true;
 FindParams.searchFields = ["*"];
 FindParams.searchText = findTxt.text;
 findTask.execute(FindParams);  //
<!-- Find Tasks -->
            <esri:FindTask id="findTask" showBusyCursor="true" 
 executeComplete="{findHandler(event);}"
 url="rest/api/server..."/>


private function findHandler(event:FindEvent):void {
 myGraphicsLayer.clear();  
 //resultSummary.text = "Results found: " + event.findResults.length;  
 myGraphicsLayer.symbol = sfsFind;
 var resultCount:int = event.findResults.length;
 if (resultCount == 0) {
       Alert.show("Search not found. \nPlease select the correct \nradio button and retry!");
 } else {
              var myFeatures:ArrayCollection = new ArrayCollection();
  for(var k:int=0; k < resultCount; k++){ 
               var cntr2:Number = (k+1);
   bottomPanel.title = "Length of features : " + resultCount.toString();
   myFeatures.addItem(
    {
  COUNT: cntr2,
  YEAR_BUILT: FindResult(event.findResults).feature.attributes.YEAR_BUILT,
  UKEY: FindResult(event.findResults).feature.attributes.UKEY,    ADDRESS1: FindResult(event.findResults).feature.attributes.ADDRESS1
   }
  );
  myGrid.visible = true;
  myGrid.dataProvider = myFeatures;
  }

<mx:DataGrid id="myGrid" visible="false" width="100%" color="0x006699"
     itemClick="myGrid_itemClick(event)" editable="false">   
     <mx:columns>
      <mx:DataGridColumn width="40" dataField="COUNT" headerText="#"/>
      <mx:DataGridColumn width="45" dataField="YEAR_BUILT" headerText="Year"/>
      <mx:DataGridColumn width="45" dataField="UKEY" headerText="Key"/>
<mx:DataGridColumn dataField="ADDRESS1" headerText="City Name"/> 
     </mx:columns>
    </mx:DataGrid>


private function myGrid_itemClick(event:ListEvent):void {   
    if(event.columnIndex >= 0){
     var graphicProvider:ArrayCollection = myGraphicsLayer.graphicProvider as ArrayCollection;
     var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
     myMap.extent = graphicsExtent.expand(2.4);
     myGraphicsLayer.symbol = smsFind;
    }
   }
0 Kudos