PageRenderTime 25ms CodeModel.GetById 19ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/ArcGISLink/src/Find.mxml

http://gmaps-utility-library-flash.googlecode.com/
Macromedia eXtensible Markup Language | 155 lines | 139 code | 16 blank | 0 comment | 0 complexity | 77ba535df4df28462c1a9b45ab4e1ea1 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 Find:"
  7            width="100%"
  8            height="100%">
  9    <mx:HBox width="100%"
 10             height="100%">
 11      <mx:VBox height="100%"
 12               width="80%">
 13        <mx:HBox>
 14          <mx:Label text="Search a State, City or River with name containing text:"/>
 15          <mx:TextInput text="KS"
 16                        id="q"
 17                        maxChars="20"
 18                        width="84"/>
 19          <mx:Button label="Find"
 20                     id="find"
 21                     enabled="false"
 22                     click="findData(q.text)"/>
 23          <mx:CheckBox label="Exact Match"
 24                       id="exact"/>
 25        </mx:HBox>
 26        <mx:Label text="Running...."
 27                  id="busy"
 28                  color="#FF1200"
 29                  width="131"
 30                  visible="false"/>
 31        <maps:Map xmlns:maps="com.google.maps.*"
 32                  id="map"
 33                  mapevent_mapready="onMapReady(event)"
 34                  width="100%"
 35                  height="100%"
 36                  key="ABQIAAAA7QUChpcnvnmXxsjC7s1fCxQGj0PqsCtxKvarsoS-iqLdqZSKfxTd7Xf-2rEc_PC9o8IsJde80Wnj4g" sensor="false"/>
 37
 38
 39      </mx:VBox>
 40      <mx:List height="100%"
 41               width="20%"
 42               id="results">
 43
 44      </mx:List>
 45    </mx:HBox>
 46
 47  </mx:Panel>
 48
 49  <mx:Script>
 50    <![CDATA[
 51      import mx.events.ListEvent;
 52      import mx.controls.*;
 53      import mx.controls.dataGridClasses.*;
 54      import com.google.maps.controls.*;
 55      import com.google.maps.overlays.*;
 56      import com.google.maps.*;
 57      import com.google.maps.interfaces.*;
 58      
 59      import com.google.maps.extras.arcgislink.*;
 60      
 61
 62      private var service:MapService;
 63      private var grid:DataGrid;
 64
 65      [Bindable]
 66      private var findValues:Array=new Array();
 67      private var overlayResults:Array=new Array();
 68
 69
 70      private function onMapReady(event:Event):void {
 71        map.setCenter(new LatLng(40, -100), 4);
 72        map.addControl(new MapTypeControl());
 73        map.addControl(new NavigationControl());
 74        map.enableScrollWheelZoom();
 75        map.enableContinuousZoom();
 76        grid=new DataGrid();
 77        var c:DataGridColumn=new DataGridColumn();
 78        c.headerText='Name';
 79        c.dataField='name';
 80        var c2:DataGridColumn=new DataGridColumn();
 81        c2.headerText='Value';
 82        c2.dataField='value';
 83        grid.columns=[c, c2];
 84        //var t:List = new List();
 85        grid.width=300;
 86        grid.height=200;
 87        service=new MapService('http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer');
 88
 89        service.addEventListener(ServiceEvent.LOAD, function(evt:Event):void {
 90            find.enabled=true;
 91          });
 92         service.addEventListener(ServiceEvent.ERROR, function(evt:ServiceEvent):void{
 93           Alert.show(evt.data.toString());
 94         });
 95        results.dataProvider=findValues;
 96        results.addEventListener(ListEvent.ITEM_CLICK, function(evt:ListEvent):void {
 97            var row:int=evt.rowIndex;
 98            if (overlayResults[row]) {
 99              var ov:*=overlayResults[row];
100              ov.dispatchEvent(new MapMouseEvent(MapMouseEvent.CLICK, ov, (ov is Marker) ? (ov as Marker).getLatLng() : ov.getLatLngBounds().getCenter()));
101
102            }
103          });
104      }
105
106      private function findData(q:String):void {
107        map.clearOverlays();
108        map.closeInfoWindow();
109        var ex:Boolean=exact.selected;
110        findValues=[];
111        overlayResults=[];
112        var params:FindParameters=new FindParameters({returnGeometry: true, searchText: q, 
113        contains: !ex, layerIds: service.getLayerIdsByName(['Cities', 'Rivers', 'States']), 
114            searchFields: ["CITY_NAME", "NAME", "SYSTEM", "STATE_ABBR", "STATE_NAME"]});;
115        busy.visible=true;
116        service.find(params, processFindResults);
117      }
118
119      private function processFindResults(rs:FindResults):void {
120        busy.visible=false;
121        var fs:Array=rs.results;
122        for (var i:int=0, c:int=fs.length; i < c; i++) {
123          processFindResult(fs[i]);
124        }
125        results.dataProvider=findValues;
126      }
127
128      private function processFindResult(res:FindResult):void {
129        var title:String=res.layerName + ':' + res.foundFieldName + ' = ' + res.value;
130        var ovs:Array= res.geometry;
131        var a:*=res.attributes;
132        var html:Array=[];
133        for (var x:String in a) {
134          if (a.hasOwnProperty(x)) {
135            html.push({name: x, value: a[x]});
136          }
137        }
138        findValues.push(title);
139        for (var j:int=0, jc:int=ovs.length; j < jc; j++) {
140          var ov:*=ovs[j];
141          var idx:int = overlayResults.length;
142          ov.addEventListener(MapMouseEvent.CLICK, function(evt:MapMouseEvent):void {
143              var latlng:LatLng= evt.latLng;
144              grid.dataProvider=html;
145              var options:InfoWindowOptions=new InfoWindowOptions({customContent: grid, drawDefaultFrame: true});
146              map.openInfoWindow(latlng, options);
147              results.selectedIndex = idx;
148            });
149          overlayResults.push(ov);
150          map.addOverlay(ov);
151        }
152      }
153    ]]>
154  </mx:Script>
155</mx:Application>