Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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"
- xmlns:esri="http://www.esri.com/2008/ags" minWidth="955" minHeight="600"
- initialize="application1_initializeHandler(event)">
- <fx:Script>
- <![CDATA[
- import com.esri.ags.FeatureSet;
- import com.esri.ags.Graphic;
- import com.esri.ags.events.DrawEvent;
- import com.esri.ags.events.MapMouseEvent;
- import com.esri.ags.events.ServiceAreaEvent;
- import com.esri.ags.tasks.QueryTask;
- import com.esri.ags.tasks.supportClasses.Query;
- import mx.controls.Alert;
- import mx.events.FlexEvent;
- import mx.rpc.AsyncResponder;
- import mx.rpc.events.FaultEvent;
- [Bindable]private var facilities:FeatureSet;
- protected function popDrawTool_drawEndHandler(event:DrawEvent):void
- {
- var myQueryTask:QueryTask= new QueryTask;
- var myQuery:Query= new Query();
- myQueryTask.showBusyCursor=true;
- myQueryTask.url="http://52.4.221.163:6080/arcgis/rest/services/PopulationService/MapServer/0";
- var myQueryTask:QueryTask= new QueryTask;
- var myQuery:Query= new Query();
- myQueryTask.showBusyCursor=true;
- myQueryTask.url="http://52.4.221.163:6080/arcgis/rest/services/PopulationService/MapServer/0";
- myQueryTask.useAMF=false;
- myQuery.outSpatialReference=myMap.spatialReference;
- myQuery.returnGeometry=true;
- myQuery.geometry=event.graphic.geometry;
- myQuery.outFields = ["ID", "STATE_NAME", "TOTPOP10", "x2001_X", "x1128_X" ]; //** NOTE this only brings 2 fields from the layer, if you want more fields you have to include them here
- myQueryTask.execute(myQuery, new AsyncResponder(onResult, onFault));
- // TODO Auto-generated method stub
- function onResult(featureSet:FeatureSet, token:Object = null):void
- {
- var myTotal:int = 0;
- popQueryGraphicsLayer.clear();
- for each (var myGraphic:Graphic in featureSet.features)
- {
- }
- }
- function onFault(info:Object, token:Object = null):void
- {
- Alert.show(info.toString(), "Query Problem");
- }// end func
- }
- protected function application1_initializeHandler(event:FlexEvent):void
- {
- // TODO Auto-generated method stub
- popDrawTool.activate(DrawTool.POLYGON);
- }
- protected function myMap_mapClickHandler(event:MapMouseEvent):void
- {
- // TODO Auto-generated method stub
- // clear existing graphics on each map click
- if (facilitiesGraphicsLayer.numChildren > 0)
- {
- facilitiesGraphicsLayer.clear();
- }
- if (popQueryGraphicsLayer.numChildren > 0)
- {
- popQueryGraphicsLayer.clear();
- }
- facilities = new FeatureSet([]);
- var facility:Graphic = new Graphic(event.mapPoint);
- facilitiesGraphicsLayer.add(facility);
- facilities.features.push(facility);
- saParams.facilities = facilities;
- saTask.solve(saParams);
- }
- private function solveCompleteHandler(event:ServiceAreaEvent):void
- {
- // loop through service area polygons
- for (var i:int = 0; i < event.serviceAreaSolveResult.serviceAreaPolygons.length; i++)
- {
- var polygonGraphic:Graphic = event.serviceAreaSolveResult.serviceAreaPolygons[i];
- polygonGraphic.toolTip = polygonGraphic.attributes.Name;
- popQueryGraphicsLayer.add(polygonGraphic);
- }
- }
- private function faultHandler(event:FaultEvent):void
- {
- Alert.show(event.toString());
- facilitiesGraphicsLayer.clear();
- }
- ]]>
- </fx:Script>
- <fx:Declarations>
- <!-- Place non-visual elements (e.g., services, value objects) here -->
- <esri:Extent id="MyExtent" xmin="-13042947" ymin="3856278" xmax="-13041347" ymax="3857116">
- <esri:SpatialReference wkid="102100"/>
- </esri:Extent>
- <esri:DrawTool id="popDrawTool" fillSymbol="{sfs2}" showDrawTips="false"
- drawStart="popQueryGraphicsLayer.clear();"
- drawEnd="popDrawTool_drawEndHandler(event)"
- graphicsLayer="{popQueryGraphicsLayer}" map="{myMap}"/>
- <esri:SimpleFillSymbol id="sfs2" color="#000000" style="solid">
- <esri:outline> <esri:SimpleLineSymbol width="2" color="#FF0000"/> </esri:outline>
- </esri:SimpleFillSymbol>
- <esri:ServiceAreaTask id="saTask"
- concurrency="last"
- fault="faultHandler(event)"
- requestTimeout="30"
- showBusyCursor="true"
- solveComplete="solveCompleteHandler(event)"
- url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/NAServer/ServiceArea"/>
- <esri:ServiceAreaParameters id="saParams"
- defaultBreaks="{[1]}"
- impedanceAttribute="TravelTime"
- outSpatialReference="{myMap.spatialReference}"
- restrictionAttributes="{['Avoid Gates','Avoid Private Roads','Avoid Unpaved Roads','Divider Restriction','Driving an Automobile','Oneway','Through Traffic Prohibited']}"
- returnFacilities="false"/>
- </fx:Declarations>
- <esri:Map id="myMap" extent="{MyExtent}">
- <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
- <esri:GraphicsLayer id="popQueryGraphicsLayer"/>
- <esri:GraphicsLayer id="facilitiesGraphicsLayer"/>
- </esri:Map>
- </s:Application>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement