Support loading 1+ GPX files via imagery.xml
[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 flash.system.Security;
8         import net.systemeD.halcyon.Map;
9         import net.systemeD.halcyon.DebugURLRequest;
10         import net.systemeD.halcyon.VectorLayer;
11         import net.systemeD.potlatch2.utils.*;
12
13         private var map:Map;
14
15         public function AutoVectorBackground(map:Map) {
16             this.map = map;
17         }
18
19         public function load():void {
20             var request:DebugURLRequest = new DebugURLRequest("vectors.xml");
21             var loader:URLLoader = new URLLoader();
22             loader.addEventListener(Event.COMPLETE, onConfigLoad);
23             loader.load(request.request);
24         }
25
26         public function onConfigLoad(e:Event):void {
27             var xml:XML = XML(e.target.data);
28             for each(var set:XML in xml.set) {
29
30               // allow layers to be defined but disabled. This lets me put examples in the
31               // config file.
32               if (set.@disabled == "true") continue;
33
34               if (!(set.policyfile == undefined)) {
35                 Security.loadPolicyFile(String(set.policyfile));
36               }
37
38               var name:String = (set.name == undefined) ? null : String(set.name);
39               var loader:String = set.loader;
40               switch (loader) {
41                 case "TrackLoader":
42                   break;
43                 case "KMLImporter":
44                   break;
45                 case "GPXImporter":
46                   if (set.url) {
47                     if (set.@loaded == "true") {
48                       name ||= 'GPX file';
49                       var layer:VectorLayer = new VectorLayer(name, map, 'gpx.css');
50                       map.addVectorLayer(layer);
51                       var gpxImporter:GpxImporter = new GpxImporter(layer, layer.paint, [String(set.url)]);
52                     } else {
53                       trace("configured but not loaded isn't supported yet");
54                     }
55                   } else {
56                     trace("AutoVectorBackground: no url for GPXImporter");
57                   }
58                   break;
59
60                 case "BugLoader":
61                   if (set.url && set.apiKey) {
62                     name ||= 'Bugs';
63                     var bugLoader:BugLoader = new BugLoader(map, String(set.url), String(set.apikey), name);
64                     if (set.@loaded == "true") {
65                       bugLoader.load();
66                     }
67                   } else {
68                     trace("AutoVectorBackground: error with BugLoader");
69                   }
70                   break;
71
72                 case "BikeShopLoader":
73                   if (set.url) {
74                     name ||= 'Missing Bike Shops'
75                     var bikeShopLoader:BikeShopLoader = new BikeShopLoader(map, String(set.url), name);
76                     if (set.@loaded == "true") {
77                       bikeShopLoader.load();
78                     }
79                   } else {
80                     trace("AutoVectorBackground: no url for BikeShopLoader");
81                   }
82                   break;
83
84                 default:
85                   trace("AutoVectorBackground: unknown loader");
86               }
87             }
88         }
89     }
90 }