]> git.openstreetmap.org Git - potlatch2.git/blob - net/systemeD/potlatch2/find/FindDialog.mxml
Alter the remaining Application.application occurancies
[potlatch2.git] / net / systemeD / potlatch2 / find / FindDialog.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:TitleWindow
3         xmlns:mx="http://www.adobe.com/2006/mxml" 
4         layout="vertical" showCloseButton="true"
5         horizontalAlign="center" title="Search"
6         width="458" height="350" verticalGap="0" creationComplete="txtFind.setFocus()">
7         <mx:Script><![CDATA[
8         import flash.events.Event;
9                 import mx.core.Application;
10                 import mx.core.FlexGlobals;
11                 import mx.events.CloseEvent;
12                 import mx.events.FlexEvent;
13                 import mx.managers.PopUpManager;
14                 import mx.rpc.events.ResultEvent;
15                 import mx.rpc.http.HTTPService;
16                 import mx.controls.Alert;
17         import mx.events.ListEvent;
18                         
19                 import net.systemeD.halcyon.Globals;
20                 
21                 private var nominatim:HTTPService = new HTTPService;
22                 private var nominatimURL:String = "http://open.mapquestapi.com/nominatim/v1/search?";   // ** FIXME - this should be user-configurable
23                 private var nomOptions:Object = { addressdetails:"1", limit:"10", format:"xml" };
24         private var selectedResult:Object = {lat: "0", lon: "0"};
25
26                 [Bindable]
27         private var searchResults:XMLList;
28                                 
29                 
30                 public function init():void {
31                         PopUpManager.addPopUp(this, Application(FlexGlobals.topLevelApplication), true);
32                         PopUpManager.centerPopUp(this);
33                         this.addEventListener(CloseEvent.CLOSE, findDialog_close);
34                         
35                         var obj:SharedObject = SharedObject.getLocal("user_state");
36         
37                 }
38                 
39                 private function findDialog_close(evt:CloseEvent):void {
40                         PopUpManager.removePopUp(this);
41                 }
42
43                 private function goFetch(q:String):void {
44
45                         var searchCall:String = nominatimURL;
46                         for (var item:String in nomOptions) {
47                                 searchCall += item + "="; 
48                                 searchCall += nomOptions[item] + "&";
49                         }
50                         searchCall += "q=" + q;
51                         this.nominatim.url = searchCall
52                         this.nominatim.addEventListener(ResultEvent.RESULT, goneFetched);
53                         this.nominatim.resultFormat = 'e4x';
54
55                         this.nominatim.send();
56                         
57                 }
58                 
59                 private function goneFetched(e:ResultEvent):void {
60                         searchResults = e.result.* as XMLList;
61                 }
62
63                 protected function btnFind_clickHandler(event:MouseEvent):void {
64                         goFetch(txtFind.text);
65                 }
66
67
68                 protected function txtFind_enterHandler(event:FlexEvent):void {
69                         goFetch(txtFind.text);
70                 }
71
72         private function setSelected(evt:ListEvent):void {
73             //Alert.show(evt.itemRenderer.data.@lat);
74             selectedResult = { lat: evt.itemRenderer.data.@lat, lon: evt.itemRenderer.data.@lon };
75         }
76         
77         private function goToSelected():void {
78             FlexGlobals.topLevelApplication.theMap.updateCoordsFromLatLon(selectedResult.lat, selectedResult.lon);
79             FlexGlobals.topLevelApplication.theMap.download();
80             //FlexGlobals.topLevelApplication.theMap.redraw();
81             PopUpManager.removePopUp(this);
82         }
83         
84         
85         ]]>
86         </mx:Script>
87
88         <mx:HBox horizontalAlign="left" width="100%">
89                 <mx:Label text="Enter place name: " />
90                 <mx:TextInput id="txtFind" width="100%" enter="txtFind_enterHandler(event)"/>
91                 <mx:Button label="Search" id="btnFind" click="btnFind_clickHandler(event)"/>            
92         </mx:HBox>
93         
94         <mx:Spacer height="10"/>
95         
96         <mx:DataGrid id="dgResults" dataProvider="{searchResults}" change="setSelected(event)" width="100%" height="100%">
97                 <mx:columns>
98                         <mx:DataGridColumn headerText="Name" dataField="@display_name" minWidth="200" />
99                         <mx:DataGridColumn headerText="Type" dataField="@type"/>
100                         <mx:DataGridColumn headerText="Class" dataField="@class"/>            
101                         <mx:DataGridColumn headerText="ID" dataField="@osm_id"/>
102         </mx:columns>
103         </mx:DataGrid>
104
105     <mx:ControlBar>
106         <mx:Label text="Results from Nominatim" />
107         <mx:Spacer width="100%"/>
108         <mx:Button label="Cancel" click="PopUpManager.removePopUp(this);" styleName="titleWindowButton" />
109         <mx:Button label="Jump to" click="goToSelected();" styleName="titleWindowButton" enabled="{dgResults.selectedItem != null? true : false}" />        
110     </mx:ControlBar>
111     
112 </mx:TitleWindow>