First stub dialog for showing your own GPX traces
authorAndy Allan <gravitystorm@gmail.com>
Mon, 11 Oct 2010 17:04:01 +0000 (17:04 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Mon, 11 Oct 2010 17:04:01 +0000 (17:04 +0000)
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/potlatch2/mygpx/MyGpxDialog.mxml [new file with mode: 0644]
potlatch2.mxml

index 072dcb5..d856b8a 100755 (executable)
@@ -95,6 +95,7 @@ package net.systemeD.halcyon.connection {
                public var nodecount:int=0;
                public var waycount:int=0;
                public var relationcount:int=0;
+        private var traces:Array = [];
 
         protected function get nextNegative():Number {
             return negativeID--;
@@ -350,6 +351,7 @@ package net.systemeD.halcyon.connection {
            public function createChangeset(tags:Object):void {}
                public function closeChangeset():void {}
            public function uploadChanges():void {}
+        public function fetchUserTraces():void {}
     }
 
 }
index 24ad774..e5eaa24 100644 (file)
@@ -125,6 +125,20 @@ package net.systemeD.halcyon.connection {
             loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onStatus);
                loader.load(urlReq);
                }
+
+        private function sendOAuthGet(url:String, onComplete:Function, onError:Function, onStatus:Function):void {
+            var sig:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
+            var oauthRequest:OAuthRequest = new OAuthRequest("GET", url, null, appID, authToken);
+            var urlStr:Object = oauthRequest.buildRequest(sig, OAuthRequest.RESULT_TYPE_URL_STRING);
+
+            var urlReq:URLRequest = new URLRequest(String(urlStr));
+            urlReq.method = "GET";
+            var loader:URLLoader = new URLLoader();
+            loader.addEventListener(Event.COMPLETE, onComplete);
+            loader.addEventListener(IOErrorEvent.IO_ERROR, onError);
+            loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onStatus);
+            loader.load(urlReq);
+        }
         
         override public function uploadChanges():void {
             var changeset:Changeset = getActiveChangeset();
@@ -301,5 +315,19 @@ package net.systemeD.halcyon.connection {
             }
         }
 
+        override public function fetchUserTraces():void {
+            sendOAuthGet(Connection.apiBaseURL+"user/gpx_files",
+                         tracesLoadComplete, errorOnMapLoad, mapLoadStatus); //needs error handlers
+            dispatchEvent(new Event(LOAD_STARTED)); //specific to map or reusable?
+        }
+
+        private function tracesLoadComplete(event:Event):void {
+            //for each result in XML file
+            //  create a trace object
+            //  store in connection.traces
+            //emit event
+                        var traces:XML = new XML(URLLoader(event.target).data);
+            trace(traces);
+        }
        }
 }
diff --git a/net/systemeD/potlatch2/mygpx/MyGpxDialog.mxml b/net/systemeD/potlatch2/mygpx/MyGpxDialog.mxml
new file mode 100644 (file)
index 0000000..7ec0bde
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<mx:TitleWindow
+        xmlns:mx="http://www.adobe.com/2006/mxml"
+        layout="vertical" showCloseButton="true"
+        horizontalAlign="center" title="MyGpx Files"
+        width="600" height="400"
+        verticalGap="0">
+  <mx:Script><![CDATA[
+    import mx.managers.PopUpManager;
+    import mx.events.CloseEvent;
+    import mx.core.Application;
+
+    import net.systemeD.halcyon.connection.*;
+
+    public function init():void {
+        PopUpManager.addPopUp(this, Application(Application.application), true);
+        PopUpManager.centerPopUp(this);
+        this.addEventListener(CloseEvent.CLOSE, myGpxDialog_close);
+
+        // store whether the user has seen the help dialog before
+        var obj:SharedObject = SharedObject.getLocal("user_state");
+        obj.setProperty("help_shown","true");
+    }
+
+    private function myGpxDialog_close(evt:CloseEvent):void {
+        PopUpManager.removePopUp(this);
+    }
+
+    private function fetchList():void {
+        Connection.getConnectionInstance().fetchUserTraces();
+        results.text="yes";
+    }
+              ]]>
+  </mx:Script>
+
+  <mx:Text text="foo" id="results" />
+  <mx:Button label="fetch" click="fetchList()" />
+</mx:TitleWindow>
\ No newline at end of file
index 660b8d9..8622136 100755 (executable)
@@ -30,6 +30,7 @@
         <mx:PopUpButton id="styleButton" label="Map Style" openAlways="true"
             creationComplete="styleButton.popUp = new StyleSelector();"/>
         <mx:Button label="GPS" click="trackLoader.load();"/>
+        <mx:Button label="MyGpx" click="new MyGpxDialog().init();" />
         <mx:Spacer width="100%"/>
         <mx:Button label="Undo" click="MainUndoStack.getGlobalStack().undo();"
             enabled="{MainUndoStack.getGlobalStack().canUndo()}"/>
@@ -72,6 +73,7 @@
                import net.systemeD.potlatch2.help.*;
                import net.systemeD.potlatch2.options.*;
                import net.systemeD.potlatch2.utils.*;
+        import net.systemeD.potlatch2.mygpx.*;
                import mx.managers.PopUpManager;
                import flash.system.Security;
                import flash.net.*;