PageRenderTime 23ms CodeModel.GetById 15ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/ArcGISLink/src/MapClick.mxml

http://gmaps-utility-library-flash.googlecode.com/
Macromedia eXtensible Markup Language | 136 lines | 122 code | 14 blank | 0 comment | 0 complexity | d82785b00e1ef57365d18cb4b713ad60 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                viewSourceURL="srcview/index.html">
  5  <mx:Panel title="Map Click: Click on map to get information"
  6            width="100%"
  7            height="100%">
  8
  9
 10    <maps:Map xmlns:maps="com.google.maps.*"
 11              id="map"
 12              mapevent_mappreinitialize="onMapPreInitialize(event)"
 13              mapevent_mapready="onMapReady(event)"
 14              width="100%"
 15              height="100%"
 16			  sensor="false" key="ABQIAAAA7QUChpcnvnmXxsjC7s1fCxQGj0PqsCtxKvarsoS-iqLdqZSKfxTd7Xf-2rEc_PC9o8IsJde80Wnj4g"/>
 17  </mx:Panel>
 18  <mx:Script>
 19    <![CDATA[
 20      import com.google.maps.InfoWindowOptions;
 21      import com.google.maps.LatLng;
 22      import com.google.maps.LatLngBounds;
 23      import com.google.maps.Map;
 24      import com.google.maps.MapEvent;
 25      import com.google.maps.MapMouseEvent;
 26      import com.google.maps.MapOptions;
 27      import com.google.maps.MapType;
 28      import com.google.maps.controls.MapTypeControl;
 29      import com.google.maps.controls.NavigationControl;
 30      import com.google.maps.controls.ZoomControl;
 31      import com.google.maps.extras.arcgislink.*;
 32      import com.google.maps.interfaces.*;
 33      import com.google.maps.styles.FillStyle;
 34      
 35      import flash.display.*;
 36      
 37      import mx.collections.*;
 38      import mx.controls.*;
 39      import mx.controls.Alert;
 40      import mx.controls.dataGridClasses.*;
 41
 42      private var _svc:MapService;
 43      private var _flag:Boolean;
 44      private var _ov: ArcGISMapOverlay;
 45      private var _ovs: Array = [];
 46		
 47      private function onMapPreInitialize(event:Event):void {
 48        var url:String='http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer';
 49        _svc=new MapService(url);
 50        _svc.addEventListener(ServiceEvent.ERROR, function(evt:ServiceEvent):void{
 51           Alert.show(evt.data.toString());
 52        });
 53		_ov =new ArcGISMapOverlay(_svc, new ArcGISMapOverlayOptions({alpha: 0.5}));
 54		_ov.addEventListener(ServiceEvent.LOAD, function (evt:ServiceEvent):void{
 55			map.addOverlay(_ov);
 56			
 57		});
 58		var opts:MapOptions=new MapOptions({center: new LatLng(42.58, -83.29), zoom: 17});
 59        map.setInitOptions(opts);
 60      }
 61
 62      private function onMapReady(event:Event):void {
 63        map.enableScrollWheelZoom();
 64        map.addControl(new MapTypeControl());
 65        map.addControl(new NavigationControl());
 66        map.addEventListener(MapMouseEvent.CLICK, doIdentify);
 67      }
 68
 69      private function doIdentify(evt:MapMouseEvent):void {
 70		for (var i:int=0, c:int=_ovs.length; i < c; i++) {
 71		  map.removeOverlay(_ovs[i]);
 72		}
 73		_ovs.length = 0;
 74	    var latlng:LatLng=evt.latLng;
 75        var bnds:LatLngBounds=map.getLatLngBounds();
 76        var size:Point=map.getSize();
 77        var idParams:IdentifyParameters=new IdentifyParameters({
 78        geometry: latlng, 
 79        layerOption: 'top', tolerance: 5, bounds: bnds, width: size.x, height : size.y ,dpi:96,
 80            returnGeometry: true});
 81        _svc.identify(idParams, function processResults(res:IdentifyResults):void {
 82             if (res.results && res.results.length>0) {
 83              idWin.visible=true;
 84             
 85              idWin.title=res.results[0].layerName + ' : ' + res.results[0].value;
 86              var data:ArrayCollection=new ArrayCollection();
 87              for (var i:int=0, c:int=res.results.length; i < c; i++) {
 88                var r:IdentifyResult=res.results[i] as IdentifyResult;
 89                
 90                //layerName= r.layerName;
 91                var a:*=r.attributes;
 92                for (var x:String in a) {
 93                  if (a.hasOwnProperty(x)) {
 94                    var val:*=a[x];
 95                    val=(val === null || typeof val === 'undefined') ? '' : '' + val;
 96                    data.addItem({name: x, value: val});
 97                  }
 98                }
 99                if (r.geometry && r.geometry.length>0){
100                  for each (var ov:IOverlay in r.geometry){
101                    map.addOverlay(ov);
102					_ovs.push(ov);
103                  }
104                }
105              }
106              idResults.dataProvider=data;
107              idResults.alpha = 0.5;
108              map.openInfoWindow(latlng, new InfoWindowOptions({
109                  drawDefaultFrame: false, customContent: idWin
110                  , fillStyle:new FillStyle({alpha:0.2})
111                  }));
112            }
113          });
114      }
115    ]]>
116  </mx:Script>
117  <mx:Panel id="idWin"
118            visible="false"
119            layout="vertical"  backgroundAlpha="0.5" >
120
121    <mx:DataGrid id="idResults"
122                 width="250"
123                 height="200" >
124      <mx:columns>
125        <mx:DataGridColumn headerText="Name"
126                           dataField="name"
127                           sortable="false" />
128        <mx:DataGridColumn headerText="Value"
129                           dataField="value"
130                           sortable="false"/>
131      </mx:columns>
132    </mx:DataGrid>
133  </mx:Panel>
134
135
136</mx:Application>