I should preface this by saying that I'm a Flex newbie. Using the Samples in the Flex resource center, I've got an app running that 'Finds' parcels and zooms to them, that seems to work just fine. I have a few questions regarding the datagrid. 1) How do you code the datagrid so that it displays fields from the layer that is being searched. 2) Is it possible to find and zoom to an item displayed in the datagrid when there are multiple items in it?
I attempted to build something using Queries as opposed to Find, but I could never quite get it to work. I moved on to the Find option and it seems to be working well enough for my purposes. Any and all help/suggestions would be greatly appreciated.
Thanks,
Kevin
CODE: ========================================================================== <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:esri="http://www.esri.com/2008/ags" pageTitle="Wood County Planning Commission GIS Portal"> <s:layout> <s:VerticalLayout paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10"/> </s:layout> <fx:Script> <![CDATA[ import com.esri.ags.Graphic; import com.esri.ags.events.FindEvent; import com.esri.ags.geometry.Extent; import com.esri.ags.tasks.supportClasses.FindResult; import com.esri.ags.utils.GraphicUtil; import mx.collections.ArrayCollection; import mx.controls.Alert; private function doFind():void { findTask.execute(myFindParams); } private function executeCompleteHandler(event:FindEvent):void { myGraphicsLayer.clear(); resultSummary.text = "Found " + event.findResults.length + " results."; myGraphicsLayer.symbol = sfsFind; var resultCount:int = event.findResults.length; if (resultCount == 0) { Alert.show("No parcel found. Please change your search."); } else { // add feature as graphic to graphics layer for (var i:int = 0; i < resultCount; i++) { var graphic:Graphic = FindResult(event.findResults).feature; graphic.toolTip = event.findResults.foundFieldName + ": " + event.findResults.value; myGraphicsLayer.add(graphic); } // zoom to extent of all features var graphicProvider:ArrayCollection = myGraphicsLayer.graphicProvider as ArrayCollection; var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray()); map.extent = graphicsExtent.expand(1.1); // zoom out a little } } ]]> </fx:Script> <fx:Declarations> <!-- Symbol for Find Result as Polygon --> <esri:SimpleFillSymbol id="sfsFind" alpha="0.7"/> <!-- Find Task --> <esri:FindTask id="findTask" executeComplete="executeCompleteHandler(event)" url="http://sdeprod/ArcGIS/rest/services/Planning/MapServer"/> <esri:FindParameters id="myFindParams" contains="true" layerIds="[2]" outSpatialReference="{map.spatialReference}" returnGeometry="true" searchFields="[mpropertyNumber, DeededOwner]" searchText="{fText.text}"/> </fx:Declarations> <s:BorderContainer width="100%" height="40" backgroundColor="#87CEFA" borderVisible="true" borderColor="#191970"> <s:layout> <s:HorizontalLayout verticalAlign="middle" paddingRight="5"/> </s:layout> <s:Label text="Wood County Planning Commission" fontWeight="bold" fontSize="14" paddingLeft="10" paddingRight="620"/> <s:Label text="Search for Parcels or Owner:"/> <s:TextInput id="fText" enter="doFind()" maxWidth="400" text=""/> <s:Button click="doFind()" label="Find"/> </s:BorderContainer> <s:Label id="resultSummary" height="15"/> <mx:VDividedBox width="100%" height="100%"> <esri:Map id="map"> <esri:extent> <esri:Extent xmin="1536178" ymin="539567" xmax="1770181" ymax="720930"> <esri:SpatialReference wkid="3728"/> </esri:Extent> </esri:extent> <esri:ArcGISDynamicMapServiceLayer url="http://sdeprod/ArcGIS/rest/services/Planning/MapServer"/> <esri:GraphicsLayer id="myGraphicsLayer"/> </esri:Map> <mx:DataGrid width="100%" height="40%" dataProvider="{findTask.executeLastResult}" id="wcDataGrid"> <mx:columns> <mx:DataGridColumn dataField="layerName" headerText="Layer Name"/> <mx:DataGridColumn dataField="foundFieldName" headerText="Found Field Name"/> <mx:DataGridColumn dataField="value" headerText="Parcel Number"/> </mx:columns> </mx:DataGrid> </mx:VDividedBox> </s:Application>