adding nominatim to P2
authorAntony Pegg <antthelimey@gmail.com>
Thu, 21 Apr 2011 12:24:25 +0000 (08:24 -0400)
committerAntony Pegg <antthelimey@gmail.com>
Thu, 21 Apr 2011 12:24:25 +0000 (08:24 -0400)
net/systemeD/potlatch2/find/FindDialog.mxml [new file with mode: 0644]
potlatch2.mxml

diff --git a/net/systemeD/potlatch2/find/FindDialog.mxml b/net/systemeD/potlatch2/find/FindDialog.mxml
new file mode 100644 (file)
index 0000000..dbf9f2b
--- /dev/null
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="utf-8"?>
+<mx:TitleWindow
+       xmlns:mx="http://www.adobe.com/2006/mxml" 
+       layout="vertical" showCloseButton="true"
+       horizontalAlign="center" title="Find a place in OpenStreetMap (powered by Nominatim Search)"
+       width="458" height="350" verticalGap="0">
+       <mx:Script><![CDATA[
+               import mx.core.Application;
+               import mx.events.CloseEvent;
+               import mx.events.FlexEvent;
+               import mx.managers.PopUpManager;
+               import mx.rpc.events.ResultEvent;
+               import mx.rpc.http.HTTPService;
+               import mx.controls.Alert;
+               
+               import net.systemeD.halcyon.Globals;
+               
+               private var nominatim:HTTPService = new HTTPService;
+               private var nominatimURL:String = "http://open.mapquestapi.com/nominatim/v1/search?";
+               private var nomOptions:Object = { addressdetails:"1", limit:"10", format:"xml" };
+
+               [Bindable]
+        private var searchResults:XMLList;
+                               
+               
+               public function init():void {
+                       PopUpManager.addPopUp(this, Application(Application.application), true);
+                       PopUpManager.centerPopUp(this);
+                       this.addEventListener(CloseEvent.CLOSE, findDialog_close);
+                       
+                       var obj:SharedObject = SharedObject.getLocal("user_state");
+       
+               }
+               
+               private function findDialog_close(evt:CloseEvent):void {
+                       PopUpManager.removePopUp(this);
+               }
+
+               private function goFetch(q:String):void {
+
+                       var searchCall:String = nominatimURL;
+                       for (var item:String in nomOptions) {
+                               searchCall += item + "="; 
+                               searchCall += nomOptions[item] + "&";
+                       }
+                       searchCall += "q=" + q;
+                       this.nominatim.url = searchCall
+                       this.nominatim.addEventListener(ResultEvent.RESULT, goneFetched);
+                       this.nominatim.resultFormat = 'e4x';
+
+                       this.nominatim.send();
+                       
+               }
+               
+               private function goneFetched(e:ResultEvent):void {
+                       var resultXML:XML = e.result as XML;
+            var resultList:XMLList = resultXML..place as XMLList;
+                       //Alert.show(resultXML);
+            searchResults = e.result..place as XMLList;
+            var sr2:XMLList = e.result.searchresults as XMLList;
+            var sr3:XMLList = e.result.searchresults.place as XMLList;
+            
+            //Alert.show(searchResults);
+
+            Alert.show("SR1 = " + searchResults.length);
+            Alert.show("SR2 = " + sr2.length());
+            Alert.show("SR3 = " + sr3.length());
+            Alert.show("SR4 = " + resultList.length());            
+               }
+
+               protected function btnFind_clickHandler(event:MouseEvent):void
+               {
+                       goFetch(txtFind.text);
+               }
+
+
+               protected function txtFind_enterHandler(event:FlexEvent):void
+               {
+                       goFetch(txtFind.text);
+               }
+
+       ]]>
+       </mx:Script>
+       
+       <mx:ControlBar>
+               <mx:Spacer width="100%"/>
+               <mx:Button label="close" click="PopUpManager.removePopUp(this);" styleName="titleWindowButton" />
+       </mx:ControlBar>
+
+       <mx:HBox>
+               <mx:TextInput id="txtFind" width="250" enter="txtFind_enterHandler(event)"/>
+               <mx:Button label="Find" id="btnFind" click="btnFind_clickHandler(event)"/>              
+       </mx:HBox>
+       
+       <mx:Spacer height="20"/>
+       
+       <mx:DataGrid id="dgResults" dataProvider="{searchResults}">
+               <mx:columns>
+                       <mx:DataGridColumn headerText="Name" dataField="@display_name"/>
+               </mx:columns>
+       </mx:DataGrid>
+
+
+</mx:TitleWindow>
\ No newline at end of file
index 72153cc..cb680f2 100644 (file)
@@ -53,6 +53,7 @@
         <mx:Button id="redo" label="Redo" click="MainUndoStack.getGlobalStack().redo();" styleName="appBarButton"
             enabled="{MainUndoStack.getGlobalStack().canRedo()}"/>
         <mx:Spacer width="100%"/>
+        <mx:Button id="findButton" label="Find" click="new FindDialog().init();" styleName="appBarButton" />           
         <mx:Button id="helpButton" label="Help" click="new HelpDialog().init();" styleName="appBarButton" />
         <mx:Button id="optionsButton" label="Options" click="new OptionsDialog().init();" styleName="appBarButton" />
         <mx:Button label="Save" icon="@Embed('embedded/upload.svg')" disabledIcon="@Embed('embedded/upload_disabled.svg')" styleName="appBarButton"
         import mx.core.DragSource;
         import mx.controls.Alert;
         import com.mindspace.l10n.events.LocaleEvent;
+               
+               import net.systemeD.potlatch2.find.*;
 
         public var theMap:Map;
         public var theController:EditController;