Rework BikeShopLoader/Layer so that it responds to loadBbox calls
authorAndy Allan <andy@gravitystorm.co.uk>
Mon, 23 May 2011 17:49:56 +0000 (18:49 +0100)
committerAndy Allan <andy@gravitystorm.co.uk>
Mon, 23 May 2011 17:49:56 +0000 (18:49 +0100)
net/systemeD/potlatch2/utils/BikeShopConnection.as [new file with mode: 0644]
net/systemeD/potlatch2/utils/BikeShopLoader.as

diff --git a/net/systemeD/potlatch2/utils/BikeShopConnection.as b/net/systemeD/potlatch2/utils/BikeShopConnection.as
new file mode 100644 (file)
index 0000000..ff262ae
--- /dev/null
@@ -0,0 +1,50 @@
+package net.systemeD.potlatch2.utils {
+
+    import net.systemeD.halcyon.connection.Connection;
+    import net.systemeD.halcyon.connection.Marker;
+    import com.adobe.serialization.json.JSON;
+    import flash.system.Security;
+    import flash.net.*;
+    import flash.events.*;
+
+    public class BikeShopConnection extends Connection {
+
+        public function BikeShopConnection(cname:String,api:String,policy:String,initparams:Object=null) {
+            super(cname,api,policy,initparams);
+        }
+
+        public override function loadBbox(left:Number, right:Number, top:Number, bottom:Number):void {
+
+            // Should be guarded against multiple calls really.
+            if (policyURL != "") { Security.loadPolicyFile(policyURL); }
+
+            var loader:URLLoader = new URLLoader();
+            loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, balls);
+            loader.addEventListener(Event.COMPLETE, parseKML);
+            loader.load(new URLRequest(apiBaseURL+"shop/missing.kml?bbox="+left+","+bottom+","+right+","+top));
+        }
+
+        public function balls(event:SecurityErrorEvent):void {
+        }
+
+        private function parseKML(event:Event):void {
+            //trace(event.target.data);
+            default xml namespace = new Namespace("http://www.opengis.net/kml/2.2");
+            var kml:XML = new XML(event.target.data);
+            //trace(kml.attributes());
+            //var document:XMLList = kml.Document;
+            for each (var placemark:XML in kml..Placemark) {
+              trace("name:"+placemark.name);
+              var coords:Array = placemark..coordinates.split(",");
+              var lon:Number = coords[0];
+              var lat:Number = coords[1];
+              //var ele:Number = coords[2];
+              var tags:Object = {};
+              tags["name"] = String(placemark.name);
+              tags["description"] = String(placemark.description);
+              var marker:Marker = createMarker(tags, lat, lon);
+            }
+            default xml namespace = new Namespace("");
+        }
+    }
+}
\ No newline at end of file
index b09946f..87996f3 100644 (file)
@@ -33,51 +33,14 @@ package net.systemeD.potlatch2.utils {
             this.map = map;
             this.bikeShopBaseURL = url;
             this.name = name;
-            this.connection = new Connection(name,url,null,null);
+            this.connection = new BikeShopConnection(name,url,bikeShopBaseURL+"crossdomain.xml",null);
         }
 
         public function load():void {
-            // this would be better if the connection did the loading
-            var loader:URLLoader = new URLLoader();
-            loader.load(new URLRequest(bikeShopBaseURL+"shop/missing.kml?bbox="+map.edge_l+","+map.edge_b+","+map.edge_r+","+map.edge_t));
-            loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, balls);
-            loader.addEventListener(Event.COMPLETE, parseKML);
-        }
-
-        public function balls(event:SecurityErrorEvent):void {
-            trace(event);
-        }
-
-        private function parseKML(event:Event):void {
-            //trace(event.target.data);
-            default xml namespace = new Namespace("http://www.opengis.net/kml/2.2");
-            var kml:XML = new XML(event.target.data);
-            //trace(kml.attributes());
-            //var document:XMLList = kml.Document;
-            for each (var placemark:XML in kml..Placemark) {
-              trace("name:"+placemark.name);
-              var coords:Array = placemark..coordinates.split(",");
-              var lon:Number = coords[0];
-              var lat:Number = coords[1];
-              //var ele:Number = coords[2];
-              var tags:Object = {};
-              tags["name"] = String(placemark.name);
-              tags["description"] = String(placemark.description);
-              var marker:Marker = connection.createMarker(tags, lat, lon);
-            }
-                       default xml namespace = new Namespace("");
-            layer.updateEntityUIs(true, false);
-        }
-
-        private function get layer():MapPaint {
             if (!_layer) {
-              // this should be done by the connection, not here.
-              var policyFile:String = bikeShopBaseURL+"crossdomain.xml";
-              Security.loadPolicyFile(policyFile);
-
-              _layer = map.addLayer(connection, STYLESHEET);
+                _layer = map.addLayer(connection, STYLESHEET);
             }
-            return _layer;
+            connection.loadBbox(map.edge_l, map.edge_r, map.edge_t, map.edge_b);
         }
     }
 }
\ No newline at end of file