PageRenderTime 26ms CodeModel.GetById 22ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/ArcGISLink/src/LayerQuery3.mxml

http://gmaps-utility-library-flash.googlecode.com/
Macromedia eXtensible Markup Language | 103 lines | 90 code | 13 blank | 0 comment | 0 complexity | 7c5d1ca0823ea2f1968b43b383055ad4 MD5 | raw file
  1<?xml version="1.0" encoding="utf-8"?>
  2<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3                layout="absolute"
  4                width="100%"
  5                height="100%">
  6  <mx:Panel title="Layer Query"
  7            width="100%"
  8            height="100%">
  9	  <mx:HBox>
 10		  <mx:Label text="Pick a date:"/>
 11		  <mx:DateField width="135" id="date311" displayedMonth="8" displayedYear="2009" showToday="false" enabled="true" includeInLayout="true" selectedDate="{new Date (2009, 8, 9)}" toolTip="Select a date" editable="true"/>
 12		  <mx:Button label="Load Incidents"  click="onLoadClick(event)"/>
 13	  </mx:HBox>
 14   
 15     <maps:Map xmlns:maps="com.google.maps.*"
 16              id="map"
 17              mapevent_mapready="onMapReady(event)"
 18              width="100%"
 19              height="100%"
 20              key="ABQIAAAA7QUChpcnvnmXxsjC7s1fCxQGj0PqsCtxKvarsoS-iqLdqZSKfxTd7Xf-2rEc_PC9o8IsJde80Wnj4g" sensor="false"/>
 21  </mx:Panel>
 22
 23  <mx:Script>
 24    <![CDATA[
 25      import com.google.maps.*;
 26      import com.google.maps.controls.*;
 27      import com.google.maps.extras.arcgislink.*;
 28      import com.google.maps.interfaces.*;
 29      import com.google.maps.overlays.*;
 30      
 31      import mx.controls.Alert;
 32
 33
 34
 35      private var layer:Layer;
 36      
 37      private function onMapReady(event:Event):void {
 38        map.setCenter(new LatLng(37.76, -122.45), 13);
 39        map.addControl(new com.google.maps.controls.MapTypeControl());
 40        map.addControl(new NavigationControl());
 41        map.enableScrollWheelZoom();
 42        map.enableContinuousZoom();
 43        layer=new Layer('http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/MapServer/0');
 44        //layer.addEventListener(ServiceEvent.LOAD, initFunctionality);
 45      }
 46
 47      private function loadFeatures():void {
 48		var where:String = "req_date = '"+DateField.dateToString(this.date311.selectedDate, this.date311.formatString)+"'";
 49        var params:QueryParameters=new QueryParameters({returnGeometry: true, where: where, outFields: ['*']});
 50		map.clearOverlays();  
 51		layer.query(params, processResultSet, handleError, null);
 52      }
 53
 54      private function processResultSet(rs:ResultSet):void {
 55		
 56        var fs:Array=rs.features;
 57        for (var i:int=0, c:int=fs.length; i < c; i++) {
 58          var ovs:Array=createGMarkers(fs[i], rs.spatialReference);
 59          for (var j:int=0; j < ovs.length; j++) {
 60            map.addOverlay(ovs[j]);
 61          }
 62        }
 63      }
 64
 65      private function createGMarkers(feat:Feature, sr:SpatialReference):Array {
 66        var a:*=feat.attributes;
 67        var ovs:Array=feat.geometry;
 68		var html:String="<div id='iwdiv'>";
 69		for (var x:String in a) {
 70			if (a.hasOwnProperty(x)) {
 71				var val:*=a[x];
 72				val=(val === null || typeof val === 'undefined') ? '' : '' + val;
 73				html +="<b>"+ x +"</b>: "+val+"<br/>";
 74			}
 75		}
 76        html+="</div>";
 77		var io:InfoWindowOptions = new InfoWindowOptions({contentHTML: html, pointOffset:new Point(2, -20)});
 78        // note  it is possible each feature has more than one poly.
 79        for (var j:int=0, jc:int=ovs.length; j < jc; j++) {
 80          var ov:Marker=ovs[j] as Marker;
 81          ov.addEventListener(MapMouseEvent.ROLL_OVER, function(event:MapMouseEvent):void {
 82			  map.openInfoWindow(ov.getLatLng(), io);
 83            });
 84          ov.addEventListener(MapMouseEvent.ROLL_OUT, function(event:MapMouseEvent):void {
 85			 // map.closeInfoWindow();
 86            });
 87          ov.addEventListener(MapMouseEvent.CLICK, function(event:MapMouseEvent):void {
 88              map.openInfoWindow(event.latLng, io);
 89            });
 90        }
 91        return ovs;
 92      }
 93		private function onLoadClick(event:Event):void{
 94			loadFeatures();
 95		}
 96		
 97
 98      private function handleError(err:ServiceError):void {
 99        mx.controls.Alert.show(err.toString());
100      }
101    ]]>
102  </mx:Script>
103</mx:Application>