Merge branch 'master' into history
[potlatch2.git] / net / systemeD / potlatch2 / utils / BugLoader.as
index fcbc2a4..d9caabc 100644 (file)
@@ -1,62 +1,39 @@
 package net.systemeD.potlatch2.utils {
 
     import net.systemeD.halcyon.Map;
-    import net.systemeD.halcyon.VectorLayer;
+    import net.systemeD.halcyon.MapPaint;
     import net.systemeD.halcyon.connection.Marker;
-    import net.systemeD.potlatch2.BugLayer;
+    import net.systemeD.potlatch2.BugConnection;
     import flash.net.*;
     import flash.events.*;
-    import com.adobe.serialization.json.JSON;
+    import flash.system.Security;
 
     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";
+        private var bugDetailsURL:String;
+        private var _layer:MapPaint;
+        private var name:String;
+        private static const STYLESHEET:String="stylesheets/bugs.css";
+        private var connection:BugConnection;
 
-        public function BugLoader(map:Map, url:String, bugApiKey:String):void {
+
+        public function BugLoader(map:Map, url:String, bugApiKey:String, name:String, details:String = ''):void {
             this.map = map;
             this.bugBaseURL = url;
             this.bugApiKey = bugApiKey;
+            this.name = name;
+            this.bugDetailsURL = details;
+            connection = new BugConnection(name, url, bugApiKey, details);
+            _layer = map.addLayer(connection, STYLESHEET, true, true);
+            _layer.visible = false;
         }
 
         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);
-        }
-
-        private function parseJSON(event:Event):void {
-            var result:String = String(event.target.data);
-            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;
-              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) {
-                var n:String='Bugs';
-                _layer=new BugLayer(n,map,STYLESHEET,bugBaseURL,bugApiKey);
-                map.addVectorLayer(_layer);
-            }
-            return _layer;
+            _layer.visible = true;
+            connection.loadBbox(map.edge_l, map.edge_r, map.edge_t, map.edge_b);
         }
     }
 }
\ No newline at end of file