the bug layer should autmatically download when panning. Move the loading/parsing...
[potlatch2.git] / net / systemeD / potlatch2 / utils / BugLoader.as
index ec771dd72bbbbb45d85eb0af4eefeadda5d670b6..bebd7db7a3b5db0a1cf5bff92d4da9948fc478fd 100644 (file)
@@ -2,10 +2,11 @@ package net.systemeD.potlatch2.utils {
 
     import net.systemeD.halcyon.Map;
     import net.systemeD.halcyon.VectorLayer;
-    import net.systemeD.halcyon.connection.Node;
+    import net.systemeD.halcyon.connection.Marker;
+    import net.systemeD.potlatch2.BugLayer;
     import flash.net.*;
     import flash.events.*;
-    import com.adobe.serialization.json.JSON;
+    import flash.system.Security;
 
     public class BugLoader {
 
@@ -15,42 +16,24 @@ package net.systemeD.potlatch2.utils {
         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;
+            var policyFile:String = bugBaseURL+"crossdomain.xml";
+            Security.loadPolicyFile(policyFile);
         }
 
         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);
+            layer.loadBbox(map.edge_l, map.edge_r, map.edge_t, map.edge_b);
         }
 
-        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);
+                _layer=new BugLayer(n,map,STYLESHEET,bugBaseURL,bugApiKey);
                 map.addVectorLayer(_layer);
             }
             return _layer;