First stab at displaying bugs
authorAndy Allan <gravitystorm@gmail.com>
Tue, 16 Nov 2010 15:00:55 +0000 (15:00 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Tue, 16 Nov 2010 15:00:55 +0000 (15:00 +0000)
net/systemeD/potlatch2/utils/BugLoader.as [new file with mode: 0644]
potlatch2.mxml
resources/bugs.css [new file with mode: 0644]
resources/features/bugs/fixed.png [new file with mode: 0644]
resources/features/bugs/invalid.png [new file with mode: 0644]
resources/features/bugs/open.png [new file with mode: 0644]
resources/stylesheets.xml

diff --git a/net/systemeD/potlatch2/utils/BugLoader.as b/net/systemeD/potlatch2/utils/BugLoader.as
new file mode 100644 (file)
index 0000000..ec771dd
--- /dev/null
@@ -0,0 +1,59 @@
+package net.systemeD.potlatch2.utils {
+
+    import net.systemeD.halcyon.Map;
+    import net.systemeD.halcyon.VectorLayer;
+    import net.systemeD.halcyon.connection.Node;
+    import flash.net.*;
+    import flash.events.*;
+    import com.adobe.serialization.json.JSON;
+
+    public class BugLoader {
+
+        private var map:Map;
+        private var bugBaseURL:String;
+        private var bugApiKey:String;
+        private var _layer:VectorLayer;
+        private static const STYLESHEET:String="bugs.css";
+
+        public function BugLoader(map:Map, url:String, bugApiKey:String):void {
+            this.map = map;
+            this.bugBaseURL = url;
+            this.bugApiKey = bugApiKey;
+        }
+
+        public function load():void {
+            var loader:URLLoader = new URLLoader();
+            loader.load(new URLRequest(bugBaseURL+"getBugs.json?bbox="+map.edge_l+","+map.edge_b+","+map.edge_r+","+map.edge_t+"&key="+bugApiKey));
+            loader.addEventListener(Event.COMPLETE, parseJSON);
+        }
+
+        public function parseJSON(event:Event):void {
+            trace("parseJSON");
+            var result:String = String(event.target.data);
+            var featureCollection:Object = JSON.decode(result);
+            trace(featureCollection);
+            trace(featureCollection.type);
+            trace(featureCollection.features[0].type);
+            trace(featureCollection.features.length);
+            for each (var feature:Object in featureCollection.features) {
+              // geoJSON spec is x,y,z i.e. lon, lat, ele
+              var lon:Number = feature.geometry.coordinates[0];
+              var lat:Number = feature.geometry.coordinates[1];
+              trace(lat, lon);
+              var node:Node = layer.createNode({"name":"No right turn"}, lat, lon);
+              layer.registerPOI(node);
+            }
+            layer.paint.updateEntityUIs(layer.getObjectsByBbox(map.edge_l,map.edge_r,map.edge_t,map.edge_b), false, false);
+            //var json:Array =
+        }
+
+        private function get layer():VectorLayer {
+            if (!_layer) {
+                var n:String='Bugs';
+                _layer=new VectorLayer(n,map,STYLESHEET);
+                map.addVectorLayer(_layer);
+            }
+            return _layer;
+        }
+    }
+}
\ No newline at end of file
index 2b6aad5..7578d77 100644 (file)
@@ -37,6 +37,7 @@
                                </mx:Array>
                        </mx:dataProvider>
                </mx:PopUpMenuButton>
+        <mx:Button label="Bugs" click="bugLoader.load();" />
         <mx:Spacer width="100%"/>
         <mx:Button label="Undo" click="MainUndoStack.getGlobalStack().undo();"
             enabled="{MainUndoStack.getGlobalStack().canUndo()}"/>
@@ -98,6 +99,7 @@
                public var yahoo:Yahoo;
                public var trackLoader:TrackLoader;
                public var toolbox:Toolbox;
+        public var bugLoader:BugLoader;
 
                private var savecount:uint=0;
                private var loadcount:uint=0;
                        // create GPS trackloader
                        trackLoader=new TrackLoader(theMap,conn.apiBase);
 
+            // create Bug loader
+            bugLoader = new BugLoader(theMap,'', 'fooKey456789');
+
             // Force authentication on startup, if required
             // force_auth == force => checks for access token, and displays OAuth panel if needed
             var force_auth:String = loaderInfo.parameters["force_auth"];
diff --git a/resources/bugs.css b/resources/bugs.css
new file mode 100644 (file)
index 0000000..2c336fc
--- /dev/null
@@ -0,0 +1,3 @@
+node  { z-index: 2;
+            icon-image: features/bugs/open.png;
+            text-offset: 14; font-family: DejaVu; text: name; font-size: 9; text_color: red; }
\ No newline at end of file
diff --git a/resources/features/bugs/fixed.png b/resources/features/bugs/fixed.png
new file mode 100644 (file)
index 0000000..99c265b
Binary files /dev/null and b/resources/features/bugs/fixed.png differ
diff --git a/resources/features/bugs/invalid.png b/resources/features/bugs/invalid.png
new file mode 100644 (file)
index 0000000..35bddf1
Binary files /dev/null and b/resources/features/bugs/invalid.png differ
diff --git a/resources/features/bugs/open.png b/resources/features/bugs/open.png
new file mode 100644 (file)
index 0000000..4432db9
Binary files /dev/null and b/resources/features/bugs/open.png differ
index 6752518..c9abed1 100644 (file)
@@ -17,4 +17,8 @@
         <name>GPS</name>
         <url>gpx.css</url>
     </stylesheet>
+    <stylesheet>
+        <name>Bugs</name>
+        <url>bugs.css</url>
+    </stylesheet>
 </stylesheets>