/examples/ArcGISLink/src/LayerQuery3D.mxml

http://gmaps-utility-library-flash.googlecode.com/ · Macromedia eXtensible Markup Language · 102 lines · 89 code · 13 blank · 0 comment · 0 complexity · e3437aaf9fc769600527290d4965fcee MD5 · raw file

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3. xmlns:maps="com.google.maps.*"
  4. layout="absolute"
  5. width="100%"
  6. height="100%"
  7. viewSourceURL="srcview/index.html">
  8. <mx:Panel title="Census Data from ArcGIS Server Service: After load you should see NC county polygons, mouse over a county for name, click for data"
  9. width="100%"
  10. height="100%">
  11. <maps:Map3D id="map"
  12. sensor="false"
  13. mapevent_mapready="onMapReady(event)"
  14. mapevent_mappreinitialize="onMapPreinitialize(event);"
  15. width="100%"
  16. height="100%"
  17. key="ABQIAAAA7QUChpcnvnmXxsjC7s1fCxQGj0PqsCtxKvarsoS-iqLdqZSKfxTd7Xf-2rEc_PC9o8IsJde80Wnj4g"/>
  18. </mx:Panel>
  19. <mx:Script>
  20. <![CDATA[
  21. import mx.events.ListEvent;
  22. import mx.controls.Alert;
  23. import com.google.maps.*;
  24. import com.google.maps.geom.*;
  25. import com.google.maps.controls.*;
  26. import com.google.maps.overlays.*;
  27. import com.google.maps.interfaces.*;
  28. import com.google.maps.extras.arcgislink.*;
  29. private var svcUrl:String="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer";
  30. private var countyLayer:Layer;
  31. private var hStyle:OverlayOptions=new OverlayOptions({polygon: new PolygonOptions({fillStyle: {color: 0xffff00, alpha: 0.35}, strokeStyle: {color: 0xFF0000, thickness: 4}})});
  32. private var style:OverlayOptions=new OverlayOptions({polygon: new PolygonOptions({fillStyle: {color: 0x888888, alpha: 0.35}, strokeStyle: {color: 0x0000ff, thickness: 1}})});
  33. private function onMapPreinitialize(event:MapEvent):void {
  34. map.setInitOptions(new MapOptions({viewMode: View.VIEWMODE_PERSPECTIVE, attitude: new Attitude(20, 30, 0)}));
  35. }
  36. private function onMapReady(event:Event):void {
  37. map.setCenter(new LatLng(35.7, -79.5), 7);
  38. map.addControl(new com.google.maps.controls.MapTypeControl());
  39. map.addControl(new NavigationControl());
  40. map.enableScrollWheelZoom();
  41. map.enableContinuousZoom();
  42. countyLayer=new Layer(svcUrl + '/3');
  43. countyLayer.addEventListener(ServiceEvent.LOAD, initFunctionality);
  44. }
  45. private function initFunctionality(evt:Event):void {
  46. var params:QueryParameters=new QueryParameters({returnGeometry: true, where: "STATE_NAME = 'North Carolina'", outFields: ["NAME", "POP2000", "POP2007", "POP00_SQMI", "POP07_SQMI"]});
  47. countyLayer.query(params, processResultSet, handleError, style);
  48. }
  49. private function processResultSet(rs:ResultSet):void {
  50. var fs:Array=rs.features;
  51. fs.sort(function(A:*, B:*):int {
  52. return A.attributes['NAME'].localeCompare(B.attributes['NAME']);
  53. }, 1);
  54. for (var i:int=0, c:int=fs.length; i < c; i++) {
  55. var ovs:Array=createGPolys(fs[i], rs.spatialReference);
  56. for (var j:int=0; j < ovs.length; j++) {
  57. map.addOverlay(ovs[j]);
  58. }
  59. }
  60. }
  61. private function createGPolys(feat:Feature, sr:SpatialReference):Array {
  62. var a:*=feat.attributes;
  63. var ovs:Array=feat.geometry;
  64. var html:String="<div id='iwdiv'><b>" + a['NAME'] + "</b><br/>" + "<b>2000 Population: </b>" + a['POP2000'] + "<br/>" + "<b>2000 Population per Sq. Mi.: </b>" + a['POP00_SQMI'] + "<br/>" + "<b>2007 Population: </b>" + a['POP2007'] + "<br/>" + "<b>2007 Population per Sq. Mi.: </b>" + a['POP07_SQMI'] + '</div>';
  65. // note it is possible each feature has more than one poly.
  66. for (var j:int=0, jc:int=ovs.length; j < jc; j++) {
  67. var ov:Polygon=ovs[j] as Polygon;
  68. ov.addEventListener(MapMouseEvent.ROLL_OVER, function(event:MapMouseEvent):void {
  69. for (var i:int=0, ic:int=ovs.length; i < ic; i++) {
  70. (ovs[i] as Polygon).setOptions(hStyle.polygon);
  71. }
  72. });
  73. ov.addEventListener(MapMouseEvent.ROLL_OUT, function(event:MapMouseEvent):void {
  74. for (var i:int=0, ic:int=ovs.length; i < ic; i++) {
  75. (ovs[i] as Polygon).setOptions(style.polygon);
  76. }
  77. });
  78. ov.addEventListener(MapMouseEvent.CLICK, function(event:MapMouseEvent):void {
  79. map.openInfoWindow(event.latLng, new InfoWindowOptions({contentHTML: html}));
  80. });
  81. }
  82. return ovs;
  83. }
  84. private function handleError(err:ServiceError):void {
  85. mx.controls.Alert.show(err.toString());
  86. }
  87. ]]>
  88. </mx:Script>
  89. </mx:Application>