Fetch the user traces list, and display them as a grid to allow loading.
authorAndy Allan <gravitystorm@gmail.com>
Mon, 11 Oct 2010 17:04:08 +0000 (17:04 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Mon, 11 Oct 2010 17:04:08 +0000 (17:04 +0000)
Small bug in fetching - refreshing the display doesn't work great. Larger bug is that the /api/.../data calls need to be signed

net/systemeD/potlatch2/mygpx/MyGpxDialog.mxml

index bb7ae51915537887e02b0f6c2eaa738fa3885730..94dd480ec27d4168c8634d83efecab7323641b5a 100644 (file)
 
     import net.systemeD.halcyon.connection.*;
     import net.systemeD.potlatch2.save.*;
+    import net.systemeD.halcyon.Map;
+    import net.systemeD.halcyon.Globals;
+    import net.systemeD.halcyon.VectorLayer;
+    import net.systemeD.potlatch2.utils.Importer;
+    import net.systemeD.potlatch2.utils.GpxImporter;
+    import mx.controls.Alert;
+
+    private var map:Map;
 
     public function init():void {
         PopUpManager.addPopUp(this, Application(Application.application), true);
         PopUpManager.centerPopUp(this);
         this.addEventListener(CloseEvent.CLOSE, myGpxDialog_close);
+
+        map = Globals.vars.root;
     }
 
     private function myGpxDialog_close(evt:CloseEvent):void {
 
     private function fetchList():void {
         SaveManager.getAccessSorted();
-        Connection.getConnectionInstance().fetchUserTraces();
-        results.text="fetching...";
+        var conn:Connection = Connection.getConnectionInstance();
+        conn.addEventListener(Connection.TRACES_LOADED, onTracesLoaded);
+        conn.fetchUserTraces();
+        
+        results.text = "fetching...";
+    }
+
+    private function onTracesLoaded(e:Event):void {
+        results.text = "loaded!!";
+    }
+
+    [Bindable(event=Connection.TRACES_LOADED)]
+    private function get traces():Array {
+        var conn:Connection = Connection.getConnectionInstance();
+        return conn.getTraces();
+    }
+
+    public function loadFile(e:Event):void {
+        var o:Object = traces[traceGrid.selectedIndex];
+        var vectorlayer:VectorLayer=new VectorLayer(o.name,map,"gpx.css");
+        vectorlayer.url=o.url;
+        map.addVectorLayer(vectorlayer);
+        var gpx:GpxImporter=new GpxImporter(vectorlayer, vectorlayer.paint, [o.url], filesLoaded, true);
+    }
+
+    public function filesLoaded(success:Boolean,message:String=null):void {
+        if (success) {
+            dispatchEvent(new Event("layers_changed"));
+        } else {
+            Alert.show(message, 'Error', mx.controls.Alert.OK);
+        }
     }
               ]]>
   </mx:Script>
 
   <mx:Text text="foo" id="results" />
   <mx:Button label="fetch" click="fetchList()" />
+  <mx:DataGrid dataProvider="{traces}" width="100%" height="100%" id="traceGrid">
+    <mx:columns>
+            <mx:DataGridColumn editable="false" dataField="id" headerText="id" width="45"/>
+            <mx:DataGridColumn editable="false" dataField="name" headerText="filename"/>
+            <mx:DataGridColumn editable="false" dataField="url" headerText="url"/>
+            <mx:DataGridColumn editable="false">
+              <mx:itemRenderer>
+                <mx:Component>
+                  <mx:VBox>
+                    <mx:Button label="Load"
+                      click="parentDocument.loadFile(event)"/>
+                  </mx:VBox>
+                </mx:Component>
+              </mx:itemRenderer>
+            </mx:DataGridColumn>
+    </mx:columns>
+  </mx:DataGrid>
 </mx:TitleWindow>
\ No newline at end of file