<?xml version="1.0" encoding="utf-8"?> <s:Application creationComplete="creationCompleteHandler(event)" 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" width="755" height="600"> <fx:Declarations> <!-- SAMPLE DATA This is the data that will be joined to the GIS feature data. --> <s:ArrayCollection id="sampleData"> <fx:Object key="Connecticut" annualIncome="50000" averageFamlySize="5"/> <fx:Object key="California" annualIncome="75000" averageFamlySize="4"/> <fx:Object key="Colorado" annualIncome="60000" averageFamlySize="6"/> <fx:Object key="North Carolina" annualIncome="55000" averageFamlySize="3"/> <fx:Object key="South Carolina" annualIncome="65000" averageFamlySize="5"/> </s:ArrayCollection> <esri:QueryTask id="queryTask" useAMF="false" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"/> <esri:Query id="query" returnGeometry="true" text="{stateName.text}" outFields='["STATE_NAME","SUB_REGION"]'/> </fx:Declarations> <fx:Script> <![CDATA[ import com.esri.ags.FeatureSet; import com.esri.ags.Graphic; import com.esri.ags.events.QueryEvent; import mx.controls.Alert; import mx.events.DataGridEvent; import mx.events.FlexEvent; import mx.events.ListEvent; protected function creationCompleteHandler(event:FlexEvent):void { queryTask.addEventListener(QueryEvent.EXECUTE_COMPLETE, onQueryComplete) } private function executeQuery():void { queryTask.execute(query); } private function onQueryComplete(event:QueryEvent):void { var joinedResults:FeatureSet = joinData(event.featureSet, "STATE_NAME", sampleData, "key"); resultsGrid.dataProvider = joinedResults.attributes; } //--------------------------------------------------- // 1:1 JOINING FUNCTION //--------------------------------------------------- private function joinData(featureSet:FeatureSet, featureSetKeyColumn:String, relatedData:ArrayCollection, relatedDataKeyColumn:String):FeatureSet { //Loop through each feature. for each (var feature:Graphic in featureSet.features) { //Loop through related to find a match for each (var data:Object in relatedData) { //add new empty peopertys to the feature for (var property:Object in data) feature.attributes[property.toString()] = ""; //make both values UPPERCASE to compare var featureKeyValue:String = feature.attributes[featureSetKeyColumn].toString().toUpperCase(); var relatedKeyValue:String = data[relatedDataKeyColumn].toString().toUpperCase(); //compare if (featureKeyValue == relatedKeyValue) { //assign new value(s) for (var prop:Object in data) feature.attributes[prop.toString()] = data[prop.toString()].toString(); break; // get out of loop } } } return featureSet; } ]]> </fx:Script> <mx:Panel title="Query Sample" height="300" paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10" left="10" right="10" top="10"> <mx:HBox> <mx:Label text="US state name: " /> <mx:TextInput id="stateName" text="C" enabled="false" /> <mx:Button label="Get Details" click="executeQuery();" /> </mx:HBox> <mx:DataGrid id="resultsGrid" width="100%" height="100%"> </mx:DataGrid> </mx:Panel> </s:Application>
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.