the bug layer should autmatically download when panning. Move the loading/parsing...
authorAndy Allan <gravitystorm@gmail.com>
Mon, 22 Nov 2010 19:15:22 +0000 (19:15 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Mon, 22 Nov 2010 19:15:22 +0000 (19:15 +0000)
net/systemeD/potlatch2/BugLayer.as
net/systemeD/potlatch2/utils/BugLoader.as

index 0de103c..7233486 100644 (file)
@@ -5,6 +5,7 @@ package net.systemeD.potlatch2 {
     import net.systemeD.halcyon.connection.Marker;
     import flash.net.*;
     import flash.events.*;
+    import com.adobe.serialization.json.JSON;
 
     public class BugLayer extends VectorLayer {
 
@@ -15,6 +16,7 @@ package net.systemeD.potlatch2 {
         private var BUG_STATUS_OPEN:String = "1";
         private var BUG_STATUS_FIXED:String = "2";
         private var BUG_STATUS_INVALID:String = "3"; // or 'non-reproduceable'
+        private static const status:Array = ["", "open", "fixed", "invalid"];
 
         public function BugLayer(n:String, map:Map, s:String, baseUrl:String, apiKey:String) {
             this.baseUrl = baseUrl;
@@ -41,5 +43,38 @@ package net.systemeD.potlatch2 {
             trace("bug closed");
             // remove it from the layer, redraw, fix selection etc.
         }
+
+        public override function loadBbox(left:Number, right:Number,
+                                top:Number, bottom:Number):void {
+            var loader:URLLoader = new URLLoader();
+            loader.load(new URLRequest(baseUrl+"getBugs?bbox="+map.edge_l+","+map.edge_b+","+map.edge_r+","+map.edge_t+"&key="+apiKey));
+            loader.addEventListener(Event.COMPLETE, parseJSON);
+        }
+
+        private function parseJSON(event:Event):void {
+            var result:String = String(event.target.data);
+            if (result) { // api returns 204 no content for no bugs, and the JSON parser treats '' as an error
+              var featureCollection:Object = JSON.decode(result);
+
+              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];
+                var tags:Object = {};
+                tags["name"] = String(feature.properties.description).substr(0,10)+'...';
+                tags["description"] = feature.properties.description;
+                tags["bug_id"] = feature.id;
+                tags["nickname"] = feature.properties.nickname;
+                tags["type"] = feature.properties.type;
+                tags["date_created"] = feature.properties.date_created;
+                tags["date_updated"] = feature.properties.date_updated;
+                tags["source"] = feature.properties.source;
+                tags["status"] = status[int(feature.properties.status)];
+                var marker:Marker = createMarker(tags, lat, lon);
+              }
+              paint.updateEntityUIs(getObjectsByBbox(map.edge_l,map.edge_r,map.edge_t,map.edge_b), true, false);
+            }
+        }
+
     }
 }
index b26b9dd..bebd7db 100644 (file)
@@ -6,7 +6,6 @@ package net.systemeD.potlatch2.utils {
     import net.systemeD.potlatch2.BugLayer;
     import flash.net.*;
     import flash.events.*;
-    import com.adobe.serialization.json.JSON;
     import flash.system.Security;
 
     public class BugLoader {
@@ -16,7 +15,7 @@ package net.systemeD.potlatch2.utils {
         private var bugApiKey:String;
         private var _layer:VectorLayer;
         private static const STYLESHEET:String="bugs.css";
-        private static const status:Array = ["", "open", "fixed", "invalid"];
+
 
         public function BugLoader(map:Map, url:String, bugApiKey:String):void {
             this.map = map;
@@ -27,40 +26,9 @@ package net.systemeD.potlatch2.utils {
         }
 
         public function load():void {
-            var loader:URLLoader = new URLLoader();
-            loader.load(new URLRequest(bugBaseURL+"getBugs?bbox="+map.edge_l+","+map.edge_b+","+map.edge_r+","+map.edge_t+"&key="+bugApiKey));
-            loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, balls);
-            loader.addEventListener(Event.COMPLETE, parseJSON);
-        }
-
-        public function balls(event:SecurityErrorEvent):void {
-            trace(event);
+            layer.loadBbox(map.edge_l, map.edge_r, map.edge_t, map.edge_b);
         }
 
-        private function parseJSON(event:Event):void {
-            var result:String = String(event.target.data);
-            if (result) { // api returns 204 no content for no bugs, and the JSON parser treats '' as an error
-              var featureCollection:Object = JSON.decode(result);
-
-              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];
-                var tags:Object = {};
-                tags["name"] = String(feature.properties.description).substr(0,10)+'...';
-                tags["description"] = feature.properties.description;
-                tags["bug_id"] = feature.id;
-                tags["nickname"] = feature.properties.nickname;
-                tags["type"] = feature.properties.type;
-                tags["date_created"] = feature.properties.date_created;
-                tags["date_updated"] = feature.properties.date_updated;
-                tags["source"] = feature.properties.source;
-                tags["status"] = status[int(feature.properties.status)];
-                var marker:Marker = layer.createMarker(tags, lat, lon);
-              }
-              layer.paint.updateEntityUIs(layer.getObjectsByBbox(map.edge_l,map.edge_r,map.edge_t,map.edge_b), true, false);
-            }
-        }
 
         private function get layer():VectorLayer {
             if (!_layer) {