AutoVectorBackground - load VectorBackground layers from a config file
authorAndy Allan <gravitystorm@gmail.com>
Fri, 26 Nov 2010 14:41:48 +0000 (14:41 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Fri, 26 Nov 2010 14:41:48 +0000 (14:41 +0000)
net/systemeD/potlatch2/AutoVectorBackground.as [new file with mode: 0644]
potlatch2.mxml
resources/vectors.xml [new file with mode: 0644]

diff --git a/net/systemeD/potlatch2/AutoVectorBackground.as b/net/systemeD/potlatch2/AutoVectorBackground.as
new file mode 100644 (file)
index 0000000..3e93ea3
--- /dev/null
@@ -0,0 +1,49 @@
+package net.systemeD.potlatch2 {
+
+    public class AutoVectorBackground {
+
+        import flash.events.*
+        import flash.net.*
+        import net.systemeD.halcyon.Map;
+        import net.systemeD.halcyon.DebugURLRequest;
+        import net.systemeD.potlatch2.utils.BugLoader;
+
+        private var map:Map;
+
+        public function AutoVectorBackground(map:Map) {
+            this.map = map;
+        }
+
+        public function load():void {
+            var request:DebugURLRequest = new DebugURLRequest("vectors.xml");
+            var loader:URLLoader = new URLLoader();
+            loader.addEventListener(Event.COMPLETE, onConfigLoad);
+            loader.load(request.request);
+        }
+
+        public function onConfigLoad(e:Event):void {
+            var xml:XML = XML(e.target.data);
+            for each(var set:XML in xml.set) {
+              var loader:String = set.loader;
+              switch (loader) {
+                case "TrackLoader":
+                  break;
+                case "KMLImporter":
+                  break;
+                case "BugLoader":
+                  if (set.url && set.apiKey) {
+                    var bugLoader:BugLoader = new BugLoader(map, String(set.url), String(set.apikey));
+                    if (set.@loaded == "true") {
+                      bugLoader.load();
+                    }
+                  } else {
+                    trace("AutoVectorBackground: error with BugLoader");
+                  }
+                  break;
+                default:
+                  trace("AutoVectorBackground: unknown loader");
+              }
+            }
+        }
+    }
+}
\ No newline at end of file
index 61560f9..42fa40a 100644 (file)
 
                        // create map and Yahoo
                        theMap=new Map(this.loaderInfo.parameters);
+
+            // Auto-load vector backgrounds from config
+            // This could go spectacularly wrong if map.init completes before the event listener below is added
+            var vectorloader:AutoVectorBackground = new AutoVectorBackground(theMap);
+            theMap.addEventListener(MapEvent.INITIALISED, function(e:Event):void {vectorloader.load();});
+
                        theMap.backdrop=b;
                        yahoo=new Yahoo(w,h,theMap);
                        yahoo.hide();
diff --git a/resources/vectors.xml b/resources/vectors.xml
new file mode 100644 (file)
index 0000000..0149032
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<vectors>
+    <set loaded="true">
+      <name>Mapdust Bugs</name>
+      <loader>BugLoader</loader>
+      <url>http://www.mapdust.com/api/</url>
+      <apikey>e4d47b6b8c26e822a62d747b802f98ac</apikey>
+    </set>
+    <set>
+      <name>Bike Shop Locator - Missing Shops</name>
+      <loader>BikeShopLoader</loader>
+      <url>http://shaunmcdonald.dev.openstreetmap.org/bike-shop-locator/</url>
+    </set>
+    <set>
+      <name>Everyone's GPS tracks</name>
+      <loader>TrackLoader</loader>
+      <!-- doesn't need a URL -->
+    </set>
+    <set disabled="true">
+      <name>A particular GPX file</name>
+      <loader>GPXImporter</loader>
+      <url></url>
+    </set>
+</vectors>
\ No newline at end of file