The branch now loads maps again. Lots of messy code; most of the VectorLayer stuff...
[potlatch2.git] / net / systemeD / potlatch2 / collections / VectorBackgrounds.as
1 package net.systemeD.potlatch2.collections {
2
3     import flash.events.*
4     import flash.net.*
5     import flash.system.Security;
6     import net.systemeD.halcyon.Map;
7     import net.systemeD.halcyon.DebugURLRequest;
8     import net.systemeD.halcyon.VectorLayer;
9     import net.systemeD.potlatch2.utils.*;
10         
11     public class VectorBackgrounds extends EventDispatcher {
12
13         private static const GLOBAL_INSTANCE:VectorBackgrounds = new VectorBackgrounds();
14         public static function instance():VectorBackgrounds { return GLOBAL_INSTANCE; }
15
16         private var _map:Map;
17
18
19         public function init(map:Map):void {
20             _map = map;
21             var request:DebugURLRequest = new DebugURLRequest("vectors.xml");
22             var loader:URLLoader = new URLLoader();
23             loader.addEventListener(Event.COMPLETE, onConfigLoad);
24             loader.load(request.request);
25         }
26
27         public function onConfigLoad(e:Event):void {
28             var xml:XML = XML(e.target.data);
29             for each(var set:XML in xml.set) {
30
31               // allow layers to be defined but disabled. This lets me put examples in the
32               // config file.
33               if (set.@disabled == "true") continue;
34
35               if (!(set.policyfile == undefined)) {
36                 Security.loadPolicyFile(String(set.policyfile));
37               }
38
39               var name:String = (set.name == undefined) ? null : String(set.name);
40               var loader:String = set.loader;
41               switch (loader) {
42                 case "TrackLoader":
43                   break;
44                 case "KMLImporter":
45                   break;
46                 case "GPXImporter":
47                   if (set.url) {
48                     if (set.@loaded == "true") {
49                       name ||= 'GPX file';
50                                           // >>>> REFACTOR: VectorLayer commented out
51                       // var layer:VectorLayer = new VectorLayer(name, _map, 'stylesheets/gpx.css');
52                       // _map.addVectorLayer(layer);
53                       // var gpxImporter:GpxImporter = new GpxImporter(layer, layer.paint, [String(set.url)]);
54                     } else {
55                       trace("configured but not loaded isn't supported yet");
56                     }
57                   } else {
58                     trace("AutoVectorBackground: no url for GPXImporter");
59                   }
60                   break;
61
62                 case "BugLoader":
63                   if (set.url && set.apiKey) {
64                     name ||= 'Bugs';
65                     var bugLoader:BugLoader = new BugLoader(_map, String(set.url), String(set.apikey), name, String(set.details));
66                     if (set.@loaded == "true") {
67                       bugLoader.load();
68                     }
69                   } else {
70                     trace("AutoVectorBackground: error with BugLoader");
71                   }
72                   break;
73
74                 case "BikeShopLoader":
75                   if (set.url) {
76                     name ||= 'Missing Bike Shops'
77                     var bikeShopLoader:BikeShopLoader = new BikeShopLoader(_map, String(set.url), name);
78                     if (set.@loaded == "true") {
79                       bikeShopLoader.load();
80                     }
81                   } else {
82                     trace("AutoVectorBackground: no url for BikeShopLoader");
83                   }
84                   break;
85
86                 default:
87                   trace("AutoVectorBackground: unknown loader");
88               }
89             }
90         }
91     }
92 }