Select to view content in your preferred language

How to zoom to selected record on Data Grid result

4111
12
08-13-2010 12:11 PM
MayJeff
Deactivated User
Can someone show me how to zoom to selected record on data grid table instead of hightlighting the record only?  I am try to figure out using this example:
http://resources.esri.com/help//9.3/arcgisserver/apis/flex/samples/index.html?sample=QueryTask_ZoomI...

Thank you.
Tags (2)
0 Kudos
12 Replies
DanJensen
Deactivated User
Oh, I see. 
In my application, polygons actually overlap each other.  It would be impossible to tell which one I was highlighting in the datagrid without changing its color.  The alternative was to narrow the selection to the row clicked by the user displaying only that polygon on the map and that row in the datagrid, but that would force the user to re-run the query and was not the ideal situation.  This way, users of the application can click through all the selected features and take in all available information.  I also added a button to the datagrid's floating panel that allows users to zoom to all the selected records at anytime.  The button only appears when necessary and disappears when they are at the full extent of all features.

Good question.

Thanks,
-Dan
0 Kudos
DidumAbraham
Deactivated User
I encountered an error problem resulting from "OnFault" at the line with ....
queryTask.execute(query, new AsyncResponder(onResult, onFault)); ...  See attached file for error.  The error comes up when I use the original url as in the code above with posting date: 08-16-2010 09:23 AM.  Any help as to how to resolve it?

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
  xmlns:s="library://ns.adobe.com/flex/spark"
  xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
  xmlns:esri="http://www.esri.com/2008/ags"
  pageTitle="Query, then zoom to results">
 
 <fx:Script>
  <![CDATA[
   import com.esri.ags.FeatureSet;
   import com.esri.ags.Graphic;
   import com.esri.ags.geometry.Extent;
   import com.esri.ags.geometry.Polygon;
   
   import mx.controls.Alert;
   import mx.rpc.AsyncResponder;
   
   [Bindable] private var lastIdentifyResultGraphic:Graphic;
   
   private function doQuery():void
   {
    query.text = fText.text;
    query.where = "*";
    queryTask.execute(query, new AsyncResponder(onResult, onFault));
    function onResult(featureSet:FeatureSet, token:Object = null):void
    {
     // clear the graphics layer
     myGraphicsLayer.clear();
     
     if (featureSet.features.length == 0)
     {
      Alert.show("No States found. Please try again.");
     }
     else
     {
      var unionExtent:Extent;
      var myFirstGraphic:Graphic = featureSet.features[0];
      unionExtent = Polygon(myFirstGraphic.geometry).extent;
      
      for each (var myGraphic1:Graphic in featureSet.features)
      {
       myGraphicsLayer.add(myGraphic1);
       unionExtent = unionExtent.union(Polygon(myGraphic1.geometry).extent);
      }
      
      MainMap.extent = unionExtent;
     }
    }
    function onFault(info:Object, token:Object = null):void
    {
     Alert.show("-->Error Here<--" + info.toString());
    }
   }
   
   private function sfDataGrid_Click():void
   {
    var obj:Object = sfDataGrid.selectedItem;
    if (obj != null)
    {
     lastIdentifyResultGraphic = null;
     
     query.where = "CO_NAME = '" + obj["CO_NAME"] + "'";
     queryTaskZoom.execute(query, new AsyncResponder(onResult, onFault));
     
     function onResult(featureSet:FeatureSet, token:Object = null):void
     {
      lastIdentifyResultGraphic = featureSet.features[0];
      lastIdentifyResultGraphic.symbol = sfs;
      MainMap.extent = new Extent(lastIdentifyResultGraphic.geometry.extent.xmin,
       lastIdentifyResultGraphic.geometry.extent.ymin,
       lastIdentifyResultGraphic.geometry.extent.xmax,lastIdentifyResultGraphic.geometry.extent.ymax);
     }
     function onFault(info:Object, token:Object = null):void
     {
      Alert.show("Query Problem ", info.toString());
     }
    }
   }
  ]]>
 </fx:Script>
 
 <fx:Declarations>
 <!-- Symbol for Query Result as Polygon -->
 <esri:SimpleFillSymbol id="sfs" alpha="0.7" color="0xFF0000"/>
 
 <!-- Layer with US States -->
 <esri:QueryTask id="queryTask" showBusyCursor="true"
  url="http://geonexus/ArcGIS/rest/services/Boundaries/COUNTY_BORDERS_SO/MapServer/0"/>
 <esri:QueryTask id="queryTaskZoom" showBusyCursor="true"
  url="http://geonexus/ArcGIS/rest/services/Boundaries/COUNTY_BORDERS_SO/MapServer/0"/>
 
 <esri:Query id="query" text="{fText.text}" returnGeometry="true"
  outSpatialReference="{MainMap.spatialReference}">
  <esri:outFields>
   <fx:String>CO_NUMBER</fx:String>
   <fx:String>COUNTY_YEAR</fx:String>
  </esri:outFields>
 </esri:Query>
 </fx:Declarations>
   
 <mx:VDividedBox height="100%" width="100%">
  
  <mx:HBox width="100%" height="40" backgroundColor="0xDDDDFF" paddingTop="10" horizontalAlign="center">
   <mx:Text text="Search for U.S. States:"/>
   <mx:TextInput id="fText" enter="doQuery();" text="Lyon"/>
   <mx:Button label="Query" click="doQuery();" enabled="true"/>
  </mx:HBox>
  <mx:Text id="resultSummary" height="15"/>
  
  <!--The map-->
  <esri:Map id="MainMap" openHandCursorVisible="false" level="7" logoVisible="false"
   extent="{new Extent(-10884964.57, 4660003.62, -9907264.87, 5649404.52, new SpatialReference(102113))}">
   <esri:ArcGISTiledMapServiceLayer
    url="http://geonexus/ArcGIS/rest/services/Basemap/Basemap/MapServer"/>
   <esri:GraphicsLayer id="myGraphicsLayer" symbol="{sfs}" graphicProvider="{lastIdentifyResultGraphic}"/>
  </esri:Map>
  
  <mx:DataGrid id="sfDataGrid" click="sfDataGrid_Click()"
   dataProvider="{queryTask.executeLastResult.attributes}"
   scroll="true" width="100%" height="40%"/>
 </mx:VDividedBox>
 
</s:Application>
0 Kudos
JanPacina
Emerging Contributor
Hi there!
I am currently solving the same problem. Could any of you help me to modify my code using the previous examples (as they are not working for me). I am populating my Data Grid by a ComboBox - in the examples are polygons, I am using points. I would like to zoom to a reasonable extent of a point (a rock mine) selected from the Data Grid.
Thank you very much.
Jan

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark"
      
      minWidth="1024" minHeight="768" 
      xmlns:esri="http://www.esri.com/2008/ags" xmlns:mx="library://ns.adobe.com/flex/mx" 
      >
 <fx:Declarations>
  <!--Queried layer-->
  <esri:QueryTask id="queryTask"
      url="http://mapserver.ujep.cz/ArcGIS/rest/services/Projekty/Lomy/MapServer/0"/>
  
  <!--Querry the type of rock (Hornina)-->
  <esri:Query id="query" 
     where="Hornina='{typesChoose.selectedItem}'" 
     returnGeometry="true" 
     outSpatialReference="{mainMap.spatialReference}">
   <esri:outFields>
    <fx:String>Umisteni</fx:String>
    <fx:String>Majitel</fx:String>
    <fx:String>Kontakt</fx:String>
    <fx:String>Zrnitost</fx:String>
    <fx:String>Hornina</fx:String>
   </esri:outFields>
  </esri:Query>
  
 </fx:Declarations>
 
 <esri:Map id="mainMap">
  <esri:extent> 
   <esri:Extent xmax="-885425.789" ymax="-954466.567" xmin="-702106.51" ymin="-1044718.028">
    <esri:SpatialReference wkid="102067"/>
   </esri:Extent>
  </esri:extent>
  <esri:ArcGISTiledMapServiceLayer url="http://mapserver.ujep.cz/ArcGIS/rest/services/NAKI/Data200_cached/MapServer"/>
  <esri:GraphicsLayer id="myGraphicsLayer" 
       graphicProvider="{queryTask.executeLastResult.features}">
   <esri:renderer>
    <esri:SimpleRenderer>
     <esri:SimpleMarkerSymbol id="basicSmybol" color="red" style="diamond"/>
    </esri:SimpleRenderer>
   </esri:renderer>
  </esri:GraphicsLayer>      
 </esri:Map>
 
 <s:Panel top="50" right="50" id="leftPanel" width="350" height="400">
  <s:layout>
   <s:VerticalLayout 
    horizontalAlign="left"
    paddingLeft="10" 
    paddingRight="10"
    paddingTop="10" 
    paddingBottom="10" />
  </s:layout>
  
  <!--Choose the rock type-->
  <s:ComboBox id="typesChoose"
     selectedItem=" "
     width="75%"
     change="queryTask.execute(query)">
   <s:ArrayCollection>
    <fx:String>B�?idlice</fx:String>
    <fx:String>�?edič</fx:String>
    <fx:String>Rula</fx:String>
    <fx:String>Vápenec</fx:String>
    <fx:String>Žula</fx:String>
   </s:ArrayCollection>
  </s:ComboBox>
  
  <mx:DataGrid id="resultsGrid"
      width="100%"
      height="100%"
      dataProvider="{queryTask.executeLastResult.attributes}">
   
   <mx:columns>
    <mx:DataGridColumn headerText="Umíst�?ní" dataField="Umisteni" />
    <mx:DataGridColumn headerText="Majitel" dataField="Majitel" width="130"/>
    <mx:DataGridColumn headerText="Kontakt" dataField="Kontakt"/>  
   </mx:columns> 
  </mx:DataGrid>
 </s:Panel>
</s:Application>
0 Kudos