PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 20  <mx:Script>
 21    <![CDATA[
 22      import mx.events.ListEvent;
 23      import mx.controls.Alert;
 24
 25      import com.google.maps.*;
 26      import com.google.maps.geom.*;
 27      import com.google.maps.controls.*;
 28      import com.google.maps.overlays.*;
 29      import com.google.maps.interfaces.*;
 30
 31      import com.google.maps.extras.arcgislink.*;
 32
 33
 34      private var svcUrl:String="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer";
 35      private var countyLayer:Layer;
 36      private var hStyle:OverlayOptions=new OverlayOptions({polygon: new PolygonOptions({fillStyle: {color: 0xffff00, alpha: 0.35}, strokeStyle: {color: 0xFF0000, thickness: 4}})});
 37      private var style:OverlayOptions=new OverlayOptions({polygon: new PolygonOptions({fillStyle: {color: 0x888888, alpha: 0.35}, strokeStyle: {color: 0x0000ff, thickness: 1}})});
 38
 39      private function onMapPreinitialize(event:MapEvent):void {
 40        map.setInitOptions(new MapOptions({viewMode: View.VIEWMODE_PERSPECTIVE, attitude: new Attitude(20, 30, 0)}));
 41      }
 42
 43      private function onMapReady(event:Event):void {
 44        map.setCenter(new LatLng(35.7, -79.5), 7);
 45        map.addControl(new com.google.maps.controls.MapTypeControl());
 46        map.addControl(new NavigationControl());
 47        map.enableScrollWheelZoom();
 48        map.enableContinuousZoom();
 49        countyLayer=new Layer(svcUrl + '/3');
 50        countyLayer.addEventListener(ServiceEvent.LOAD, initFunctionality);
 51
 52      }
 53
 54      private function initFunctionality(evt:Event):void {
 55        var params:QueryParameters=new QueryParameters({returnGeometry: true, where: "STATE_NAME = 'North Carolina'", outFields: ["NAME", "POP2000", "POP2007", "POP00_SQMI", "POP07_SQMI"]});
 56        countyLayer.query(params, processResultSet, handleError, style);
 57      }
 58
 59      private function processResultSet(rs:ResultSet):void {
 60        var fs:Array=rs.features;
 61        fs.sort(function(A:*, B:*):int {
 62            return A.attributes['NAME'].localeCompare(B.attributes['NAME']);
 63          }, 1);
 64
 65        for (var i:int=0, c:int=fs.length; i < c; i++) {
 66          var ovs:Array=createGPolys(fs[i], rs.spatialReference);
 67          for (var j:int=0; j < ovs.length; j++) {
 68            map.addOverlay(ovs[j]);
 69          }
 70        }
 71      }
 72
 73      private function createGPolys(feat:Feature, sr:SpatialReference):Array {
 74        var a:*=feat.attributes;
 75        var ovs:Array=feat.geometry;
 76        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>';
 77        // note  it is possible each feature has more than one poly.
 78        for (var j:int=0, jc:int=ovs.length; j < jc; j++) {
 79          var ov:Polygon=ovs[j] as Polygon;
 80          ov.addEventListener(MapMouseEvent.ROLL_OVER, function(event:MapMouseEvent):void {
 81              for (var i:int=0, ic:int=ovs.length; i < ic; i++) {
 82                (ovs[i] as Polygon).setOptions(hStyle.polygon);
 83              }
 84            });
 85          ov.addEventListener(MapMouseEvent.ROLL_OUT, function(event:MapMouseEvent):void {
 86              for (var i:int=0, ic:int=ovs.length; i < ic; i++) {
 87                (ovs[i] as Polygon).setOptions(style.polygon);
 88              }
 89            });
 90          ov.addEventListener(MapMouseEvent.CLICK, function(event:MapMouseEvent):void {
 91              map.openInfoWindow(event.latLng, new InfoWindowOptions({contentHTML: html}));
 92            });
 93        }
 94        return ovs;
 95      }
 96
 97      private function handleError(err:ServiceError):void {
 98        mx.controls.Alert.show(err.toString());
 99      }
100    ]]>
101  </mx:Script>
102</mx:Application>