Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  3. xmlns:s="library://ns.adobe.com/flex/spark"
  4. xmlns:mx="library://ns.adobe.com/flex/mx"
  5. xmlns:esri="http://www.esri.com/2008/ags" minWidth="955" minHeight="600"
  6. initialize="application1_initializeHandler(event)">
  7. <fx:Script>
  8. <![CDATA[
  9. import com.esri.ags.FeatureSet;
  10. import com.esri.ags.Graphic;
  11. import com.esri.ags.events.DrawEvent;
  12. import com.esri.ags.events.MapMouseEvent;
  13. import com.esri.ags.events.ServiceAreaEvent;
  14. import com.esri.ags.tasks.QueryTask;
  15. import com.esri.ags.tasks.supportClasses.Query;
  16.  
  17. import mx.controls.Alert;
  18. import mx.events.FlexEvent;
  19. import mx.rpc.AsyncResponder;
  20. import mx.rpc.events.FaultEvent;
  21.  
  22.  
  23. [Bindable]private var facilities:FeatureSet;
  24.  
  25. protected function popDrawTool_drawEndHandler(event:DrawEvent):void
  26. {
  27. var myQueryTask:QueryTask= new QueryTask;
  28. var myQuery:Query= new Query();
  29. myQueryTask.showBusyCursor=true;
  30. myQueryTask.url="http://52.4.221.163:6080/arcgis/rest/services/PopulationService/MapServer/0";
  31. var myQueryTask:QueryTask= new QueryTask;
  32. var myQuery:Query= new Query();
  33. myQueryTask.showBusyCursor=true;
  34. myQueryTask.url="http://52.4.221.163:6080/arcgis/rest/services/PopulationService/MapServer/0";
  35. myQueryTask.useAMF=false;
  36. myQuery.outSpatialReference=myMap.spatialReference;
  37. myQuery.returnGeometry=true;
  38. myQuery.geometry=event.graphic.geometry;
  39. 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
  40.  
  41. myQueryTask.execute(myQuery, new AsyncResponder(onResult, onFault));
  42. // TODO Auto-generated method stub
  43. function onResult(featureSet:FeatureSet, token:Object = null):void
  44. {
  45. var myTotal:int = 0;
  46. popQueryGraphicsLayer.clear();
  47.  
  48. for each (var myGraphic:Graphic in featureSet.features)
  49. {
  50.  
  51. }
  52.  
  53. }
  54.  
  55. function onFault(info:Object, token:Object = null):void
  56. {
  57. Alert.show(info.toString(), "Query Problem");
  58. }// end func
  59. }
  60. protected function application1_initializeHandler(event:FlexEvent):void
  61. {
  62. // TODO Auto-generated method stub
  63. popDrawTool.activate(DrawTool.POLYGON);
  64. }
  65.  
  66. protected function myMap_mapClickHandler(event:MapMouseEvent):void
  67. {
  68. // TODO Auto-generated method stub
  69. // clear existing graphics on each map click
  70. if (facilitiesGraphicsLayer.numChildren > 0)
  71. {
  72. facilitiesGraphicsLayer.clear();
  73. }
  74. if (popQueryGraphicsLayer.numChildren > 0)
  75. {
  76. popQueryGraphicsLayer.clear();
  77. }
  78.  
  79. facilities = new FeatureSet([]);
  80.  
  81. var facility:Graphic = new Graphic(event.mapPoint);
  82. facilitiesGraphicsLayer.add(facility);
  83.  
  84. facilities.features.push(facility);
  85. saParams.facilities = facilities;
  86.  
  87. saTask.solve(saParams);
  88. }
  89. private function solveCompleteHandler(event:ServiceAreaEvent):void
  90. {
  91. // loop through service area polygons
  92. for (var i:int = 0; i < event.serviceAreaSolveResult.serviceAreaPolygons.length; i++)
  93. {
  94. var polygonGraphic:Graphic = event.serviceAreaSolveResult.serviceAreaPolygons[i];
  95. polygonGraphic.toolTip = polygonGraphic.attributes.Name;
  96. popQueryGraphicsLayer.add(polygonGraphic);
  97.  
  98. }
  99.  
  100. }
  101.  
  102. private function faultHandler(event:FaultEvent):void
  103. {
  104. Alert.show(event.toString());
  105. facilitiesGraphicsLayer.clear();
  106. }
  107. ]]>
  108. </fx:Script>
  109. <fx:Declarations>
  110. <!-- Place non-visual elements (e.g., services, value objects) here -->
  111. <esri:Extent id="MyExtent" xmin="-13042947" ymin="3856278" xmax="-13041347" ymax="3857116">
  112. <esri:SpatialReference wkid="102100"/>
  113. </esri:Extent>
  114. <esri:DrawTool id="popDrawTool" fillSymbol="{sfs2}" showDrawTips="false"
  115. drawStart="popQueryGraphicsLayer.clear();"
  116. drawEnd="popDrawTool_drawEndHandler(event)"
  117. graphicsLayer="{popQueryGraphicsLayer}" map="{myMap}"/>
  118. <esri:SimpleFillSymbol id="sfs2" color="#000000" style="solid">
  119. <esri:outline> <esri:SimpleLineSymbol width="2" color="#FF0000"/> </esri:outline>
  120. </esri:SimpleFillSymbol>
  121. <esri:ServiceAreaTask id="saTask"
  122. concurrency="last"
  123. fault="faultHandler(event)"
  124. requestTimeout="30"
  125. showBusyCursor="true"
  126. solveComplete="solveCompleteHandler(event)"
  127. url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/NAServer/ServiceArea"/>
  128. <esri:ServiceAreaParameters id="saParams"
  129. defaultBreaks="{[1]}"
  130. impedanceAttribute="TravelTime"
  131. outSpatialReference="{myMap.spatialReference}"
  132. restrictionAttributes="{['Avoid Gates','Avoid Private Roads','Avoid Unpaved Roads','Divider Restriction','Driving an Automobile','Oneway','Through Traffic Prohibited']}"
  133. returnFacilities="false"/>
  134. </fx:Declarations>
  135.  
  136. <esri:Map id="myMap" extent="{MyExtent}">
  137. <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
  138. <esri:GraphicsLayer id="popQueryGraphicsLayer"/>
  139. <esri:GraphicsLayer id="facilitiesGraphicsLayer"/>
  140. </esri:Map>
  141.  
  142. </s:Application>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement