The BikeShopLoader developed during WhereCampUK, but with the button permanently...
authorAndy Allan <gravitystorm@gmail.com>
Mon, 22 Nov 2010 12:41:34 +0000 (12:41 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Mon, 22 Nov 2010 12:41:34 +0000 (12:41 +0000)
See the BikeShopLoader.as file for documentation.

net/systemeD/potlatch2/utils/BikeShopLoader.as [new file with mode: 0644]
potlatch2.mxml
resources/bikeshops.css [new file with mode: 0644]
resources/features/bike-shop.png [new file with mode: 0644]

diff --git a/net/systemeD/potlatch2/utils/BikeShopLoader.as b/net/systemeD/potlatch2/utils/BikeShopLoader.as
new file mode 100644 (file)
index 0000000..b9ff202
--- /dev/null
@@ -0,0 +1,78 @@
+package net.systemeD.potlatch2.utils {
+
+    import net.systemeD.halcyon.Map;
+    import net.systemeD.halcyon.VectorLayer;
+    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;
+
+    /**
+    * The BikeShopLoader loads data regarding missing bike shops in the UK from the "bike-shop-locator" project.
+    * It was a quick hack undertaken during the WhereCampUK meeting in Nottingham in November 2010. It served partly
+    * as a demonstration of improving QA feedback loops within the OSM universe, but mainly as an indication
+    * that we need to rethink how these things are handled in P2. The amount of copy/paste coding going on is too
+    * high, and we should be able to make something along the lines of "imagery.xml" to define and load generic
+    * kml/geojson/georss feeds from multiple sources without having to code *Loader classes for each one.
+    *
+    * Oh, and it's possible to handle xml Namespaces without resorting to blanking them out of the raw data :-)
+    */
+
+    public class BikeShopLoader {
+
+        private var map:Map;
+        private var bikeShopBaseURL:String;
+        private var _layer:VectorLayer;
+        private static const STYLESHEET:String="bikeshops.css";
+
+        public function BikeShopLoader(map:Map, url:String) {
+            this.map = map;
+            this.bikeShopBaseURL = url;
+            var policyFile:String = bikeShopBaseURL+"crossdomain.xml";
+            trace(policyFile)
+            Security.loadPolicyFile(policyFile);
+        }
+
+        public function load():void {
+            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 = 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='Bike Shops';
+                _layer=new VectorLayer(n,map,STYLESHEET);
+                map.addVectorLayer(_layer);
+            }
+            return _layer;
+        }
+    }
+}
\ No newline at end of file
index fb1eb07..ce71e99 100644 (file)
@@ -38,6 +38,7 @@
                        </mx:dataProvider>
                </mx:PopUpMenuButton>
         <mx:Button id="bugsButton" label="Bugs" click="bugLoader.load();" visible="false"/>
+        <mx:Button id="bikeButton" label="Bike Shops" click="bikeShopLoader.load();" visible="false" />
         <mx:Spacer width="100%"/>
         <mx:Button label="Undo" click="MainUndoStack.getGlobalStack().undo();"
             enabled="{MainUndoStack.getGlobalStack().canUndo()}"/>
                public var trackLoader:TrackLoader;
                public var toolbox:Toolbox;
         public var bugLoader:BugLoader;
+        public var bikeShopLoader:BikeShopLoader;
 
                private var savecount:uint=0;
                private var loadcount:uint=0;
               bugLoader = new BugLoader(theMap, loaderInfo.parameters["bugs_url"], loaderInfo.parameters["bugs_apikey"]);
             }
 
+            // create Bike Shop loader
+            bikeShopLoader = new BikeShopLoader(theMap, 'http://shaunmcdonald.dev.openstreetmap.org/bike-shop-locator/');
+
             // 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/bikeshops.css b/resources/bikeshops.css
new file mode 100644 (file)
index 0000000..cd74a7f
--- /dev/null
@@ -0,0 +1,3 @@
+node  { z-index: 9;
+            icon-image: features/bike-shop.png;
+            text-offset: 28; font-family: DejaVu; text: name; font-size: 9; text_color: red; width: 50;}
\ No newline at end of file
diff --git a/resources/features/bike-shop.png b/resources/features/bike-shop.png
new file mode 100644 (file)
index 0000000..b7a0c68
Binary files /dev/null and b/resources/features/bike-shop.png differ