<?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:esri="http://www.esri.com/2008/ags" xmlns:s="library://ns.adobe.com/flex/spark" pageTitle="Query Task (with a map)"> <s:layout> <s:VerticalLayout gap="10" horizontalAlign="center" paddingBottom="20" paddingLeft="25" paddingRight="25" paddingTop="20"/> </s:layout> <fx:Script> <![CDATA[ import com.esri.ags.FeatureSet; import com.esri.ags.Graphic; import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.events.IndexChangedEvent; import mx.rpc.AsyncResponder; import spark.events.IndexChangeEvent; [Bindable] public var westStates:ArrayCollection = new ArrayCollection(['California','Arizona','Colorado','Washington','Oregon']); [Bindable] public var eastStates:ArrayCollection = new ArrayCollection(['New York','Pennsylvania','Virginia','Illinois','Maine']); [Bindable] public var southStates:ArrayCollection = new ArrayCollection(['Louisiana','Florida','Alabama','Mississippi','Texas']); [Bindable] public var regions:ArrayCollection = new ArrayCollection(['West','East','South']); [Bindable] public var statesArr:ArrayCollection = new ArrayCollection([westStates,eastStates,southStates]); public function changeStates(event:IndexChangeEvent):void { var index:int = event.currentTarget.selectedIndex; statesDDL.dataProvider = statesArr[index]; if(!statesDDL.enabled) { statesDDL.enabled = true; } } private function doQuery():void { queryTask.execute(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { // No code needed in this simple sample, since the // graphics layer is bound to the query result using // graphicProvider="{queryTask.executeLastResult.features}" } function onFault(info:Object, token:Object = null):void { Alert.show(info.toString(), "Query Problem"); } } ]]> </fx:Script> <fx:Declarations> <!-- Layer with US States --> <esri:QueryTask id="queryTask" showBusyCursor="true" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5" useAMF="false"/> <esri:Query id="query" outSpatialReference="{myMap.spatialReference}" returnGeometry="true" text="{statesDDL.selectedItem}"> <esri:outFields> <fx:String>MED_AGE</fx:String> <fx:String>POP2007</fx:String> </esri:outFields> </esri:Query> </fx:Declarations> <s:Panel height="60" backgroundColor="0xB2BFC6" title="Query a layer (search for a state)"> <s:layout> <s:HorizontalLayout/> </s:layout> <s:DropDownList id="regionsDDL" width="150" prompt="Select a region" dataProvider="{regions}" change="changeStates(event)"/> <s:DropDownList id="statesDDL" width="150" prompt="Select a country" enabled="false" change="queryBTN.enabled = true;"/> <s:Button id="queryBTN" click="doQuery()" enabled="false" label="Do Query"/> </s:Panel> <esri:Map id="myMap"> <esri:extent> <esri:Extent xmin="-14298000" ymin="2748000" xmax="-6815000" ymax="7117000"> <esri:SpatialReference wkid="102100"/> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Physical_Map/MapServer"/> <esri:GraphicsLayer id="myGraphicsLayer" graphicProvider="{queryTask.executeLastResult.features}"/> </esri:Map> </s:Application>
Solved! Go to Solution.
<?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:esri="http://www.esri.com/2008/ags" xmlns:s="library://ns.adobe.com/flex/spark" pageTitle="Query Task (with a map)"> <s:layout> <s:VerticalLayout gap="10" horizontalAlign="center" paddingBottom="20" paddingLeft="25" paddingRight="25" paddingTop="20"/> </s:layout> <fx:Script> <![CDATA[ import com.esri.ags.FeatureSet; import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.rpc.AsyncResponder; import spark.events.IndexChangeEvent; [Bindable] public var westStates:ArrayCollection = new ArrayCollection(['California','Arizona','Colorado','Washington','Oregon']); [Bindable] public var eastStates:ArrayCollection = new ArrayCollection(['New York','Pennsylvania','Virginia','Illinois','Maine']); [Bindable] public var southStates:ArrayCollection = new ArrayCollection(['Louisiana','Florida','Alabama','Mississippi','Texas']); [Bindable] public var regions:ArrayCollection = new ArrayCollection(['West','East','South']); [Bindable] public var statesArr:ArrayCollection = new ArrayCollection([westStates,eastStates,southStates]); [Bindable] public var alabamaCounties:ArrayCollection = new ArrayCollection(['Autauga','Baldwin','Barbour','Bibb','Blount','Bullock','Butler','Calhoun','Chambers','Cherokee','Chilton','Choctaw','Clarke','Clay','Cleburne','Coffee','Colbert','Conecuh','Coosa','Covington','Crenshaw','Cullman','Dale','Dallas','De Kalb','Elmore','Escambia','Etowah','Fayette','Franklin','Geneva','Greene','Hale','Henry','Houston','Jackson','Jefferson','Lamar','Lauderdale','Lawrence','Lee','Limestone','Lowndes','Macon','Madison','Marengo','Marion','Marshall','Mobile','Monroe','Montgomery','Morgan','Perry','Pickens','Pike','Randolph','Russell','St. Clair','Shelby','Sumter','Talladega','Tallapoosa','Tuscaloosa','Walker','Washington','Wilcox','Winston']); public function changeStates(event:IndexChangeEvent):void { var index:int = event.currentTarget.selectedIndex; statesDDL.dataProvider = statesArr[index]; if(!statesDDL.enabled) { statesDDL.enabled = true; } } private function doQuery():void { if (statesDDL.selectedItem == 'Alabama') { queryTask.url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/4"; query.where = "STATE_NAME = 'Alabama' AND NAME = '" + countiesDDL.selectedItem + "'"; } queryTask.execute(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { // No code needed in this simple sample, since the // graphics layer is bound to the query result using // graphicProvider="{queryTask.executeLastResult.features}" } function onFault(info:Object, token:Object = null):void { Alert.show(info.toString(), "Query Problem"); } } protected function statesDDL_changeHandler(event:IndexChangeEvent):void { if (statesDDL.selectedItem == 'Alabama') { countiesDDL.dataProvider = alabamaCounties; countiesDDL.enabled = true; }else{ queryBTN.enabled = true; query.text = statesDDL.selectedItem; } } ]]> </fx:Script> <fx:Declarations> <!-- Layer with US States --> <esri:QueryTask id="queryTask" showBusyCursor="true" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5" useAMF="false"/> <esri:Query id="query" outSpatialReference="{myMap.spatialReference}" returnGeometry="true"> <esri:outFields> <fx:String>MED_AGE</fx:String> <fx:String>POP2007</fx:String> </esri:outFields> </esri:Query> </fx:Declarations> <s:Panel height="60" backgroundColor="0xB2BFC6" title="Query a layer (search for a state)"> <s:layout> <s:HorizontalLayout/> </s:layout> <s:DropDownList id="regionsDDL" width="150" prompt="Select a region" dataProvider="{regions}" change="changeStates(event)"/> <s:DropDownList id="statesDDL" width="150" prompt="Select a state" enabled="false" change="statesDDL_changeHandler(event)"/> <s:DropDownList id="countiesDDL" width="150" prompt="Select a county" enabled="false" change="queryBTN.enabled = true;"/> <s:Button id="queryBTN" click="doQuery()" enabled="false" label="Do Query"/> </s:Panel> <esri:Map id="myMap"> <esri:extent> <esri:Extent xmin="-14298000" ymin="2748000" xmax="-6815000" ymax="7117000"> <esri:SpatialReference wkid="102100"/> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Physical_Map/MapServer"/> <esri:GraphicsLayer id="myGraphicsLayer" graphicProvider="{queryTask.executeLastResult.features}"/> </esri:Map> </s:Application>
<?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:esri="http://www.esri.com/2008/ags" xmlns:s="library://ns.adobe.com/flex/spark" pageTitle="Query Task (with a map)"> <s:layout> <s:VerticalLayout gap="10" horizontalAlign="center" paddingBottom="20" paddingLeft="25" paddingRight="25" paddingTop="20"/> </s:layout> <fx:Script> <![CDATA[ import com.esri.ags.FeatureSet; import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.rpc.AsyncResponder; import spark.events.IndexChangeEvent; [Bindable] public var westStates:ArrayCollection = new ArrayCollection(['California','Arizona','Colorado','Washington','Oregon']); [Bindable] public var eastStates:ArrayCollection = new ArrayCollection(['New York','Pennsylvania','Virginia','Illinois','Maine']); [Bindable] public var southStates:ArrayCollection = new ArrayCollection(['Louisiana','Florida','Alabama','Mississippi','Texas']); [Bindable] public var regions:ArrayCollection = new ArrayCollection(['West','East','South']); [Bindable] public var statesArr:ArrayCollection = new ArrayCollection([westStates,eastStates,southStates]); [Bindable] public var alabamaCounties:ArrayCollection = new ArrayCollection(['Autauga','Baldwin','Barbour','Bibb','Blount','Bullock','Butler','Calhoun','Chambers','Cherokee','Chilton','Choctaw','Clarke','Clay','Cleburne','Coffee','Colbert','Conecuh','Coosa','Covington','Crenshaw','Cullman','Dale','Dallas','De Kalb','Elmore','Escambia','Etowah','Fayette','Franklin','Geneva','Greene','Hale','Henry','Houston','Jackson','Jefferson','Lamar','Lauderdale','Lawrence','Lee','Limestone','Lowndes','Macon','Madison','Marengo','Marion','Marshall','Mobile','Monroe','Montgomery','Morgan','Perry','Pickens','Pike','Randolph','Russell','St. Clair','Shelby','Sumter','Talladega','Tallapoosa','Tuscaloosa','Walker','Washington','Wilcox','Winston']); public function changeStates(event:IndexChangeEvent):void { var index:int = event.currentTarget.selectedIndex; statesDDL.dataProvider = statesArr[index]; if(!statesDDL.enabled) { statesDDL.enabled = true; } } private function doQuery():void { if (statesDDL.selectedItem == 'Alabama') { queryTask.url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/4"; query.where = "STATE_NAME = 'Alabama' AND NAME = '" + countiesDDL.selectedItem + "'"; } queryTask.execute(query, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { // No code needed in this simple sample, since the // graphics layer is bound to the query result using // graphicProvider="{queryTask.executeLastResult.features}" } function onFault(info:Object, token:Object = null):void { Alert.show(info.toString(), "Query Problem"); } } protected function statesDDL_changeHandler(event:IndexChangeEvent):void { if (statesDDL.selectedItem == 'Alabama') { countiesDDL.dataProvider = alabamaCounties; countiesDDL.enabled = true; }else{ queryBTN.enabled = true; query.text = statesDDL.selectedItem; } } ]]> </fx:Script> <fx:Declarations> <!-- Layer with US States --> <esri:QueryTask id="queryTask" showBusyCursor="true" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5" useAMF="false"/> <esri:Query id="query" outSpatialReference="{myMap.spatialReference}" returnGeometry="true"> <esri:outFields> <fx:String>MED_AGE</fx:String> <fx:String>POP2007</fx:String> </esri:outFields> </esri:Query> </fx:Declarations> <s:Panel height="60" backgroundColor="0xB2BFC6" title="Query a layer (search for a state)"> <s:layout> <s:HorizontalLayout/> </s:layout> <s:DropDownList id="regionsDDL" width="150" prompt="Select a region" dataProvider="{regions}" change="changeStates(event)"/> <s:DropDownList id="statesDDL" width="150" prompt="Select a state" enabled="false" change="statesDDL_changeHandler(event)"/> <s:DropDownList id="countiesDDL" width="150" prompt="Select a county" enabled="false" change="queryBTN.enabled = true;"/> <s:Button id="queryBTN" click="doQuery()" enabled="false" label="Do Query"/> </s:Panel> <esri:Map id="myMap"> <esri:extent> <esri:Extent xmin="-14298000" ymin="2748000" xmax="-6815000" ymax="7117000"> <esri:SpatialReference wkid="102100"/> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Physical_Map/MapServer"/> <esri:GraphicsLayer id="myGraphicsLayer" graphicProvider="{queryTask.executeLastResult.features}"/> </esri:Map> </s:Application>