6a7a92c3556462dc2533886456248338003a9c64
[potlatch2.git] / net / systemeD / potlatch2 / AutoVectorBackground.as
1 package net.systemeD.potlatch2 {
2
3     public class AutoVectorBackground {
4
5         import flash.events.*
6         import flash.net.*
7         import net.systemeD.halcyon.Map;
8         import net.systemeD.halcyon.DebugURLRequest;
9         import net.systemeD.potlatch2.utils.*;
10
11         private var map:Map;
12
13         public function AutoVectorBackground(map:Map) {
14             this.map = map;
15         }
16
17         public function load():void {
18             var request:DebugURLRequest = new DebugURLRequest("vectors.xml");
19             var loader:URLLoader = new URLLoader();
20             loader.addEventListener(Event.COMPLETE, onConfigLoad);
21             loader.load(request.request);
22         }
23
24         public function onConfigLoad(e:Event):void {
25             var xml:XML = XML(e.target.data);
26             for each(var set:XML in xml.set) {
27               var name:String = (set.name == undefined) ? null : String(set.name);
28               var loader:String = set.loader;
29               switch (loader) {
30                 case "TrackLoader":
31                   break;
32                 case "KMLImporter":
33                   break;
34
35                 case "BugLoader":
36                   if (set.url && set.apiKey) {
37                     name ||= 'Bugs';
38                     var bugLoader:BugLoader = new BugLoader(map, String(set.url), String(set.apikey), name);
39                     if (set.@loaded == "true") {
40                       bugLoader.load();
41                     }
42                   } else {
43                     trace("AutoVectorBackground: error with BugLoader");
44                   }
45                   break;
46
47                 case "BikeShopLoader":
48                   if (set.url) {
49                     name ||= 'Missing Bike Shops'
50                     var bikeShopLoader:BikeShopLoader = new BikeShopLoader(map, String(set.url), name);
51                     if (set.@loaded == "true") {
52                       bikeShopLoader.load();
53                     }
54                   } else {
55                     trace("AutoVectorBackground: no url for BikeShopLoader");
56                   }
57                   break;
58
59                 default:
60                   trace("AutoVectorBackground: unknown loader");
61               }
62             }
63         }
64     }
65 }