Refactor BugLayer to extend connection, and rename it to BugConnection to save confusion
[potlatch2.git] / net / systemeD / potlatch2 / utils / BugLoader.as
1 package net.systemeD.potlatch2.utils {
2
3     import net.systemeD.halcyon.Map;
4     import net.systemeD.halcyon.MapPaint;
5     import net.systemeD.halcyon.connection.Marker;
6     import net.systemeD.potlatch2.BugConnection;
7     import flash.net.*;
8     import flash.events.*;
9     import flash.system.Security;
10
11     public class BugLoader {
12
13         private var map:Map;
14         private var bugBaseURL:String;
15         private var bugApiKey:String;
16         private var bugDetailsURL:String;
17         private var _layer:MapPaint;
18         private var name:String;
19         private static const STYLESHEET:String="stylesheets/bugs.css";
20         private var connection:BugConnection;
21
22
23         public function BugLoader(map:Map, url:String, bugApiKey:String, name:String, details:String = ''):void {
24             this.map = map;
25             this.bugBaseURL = url;
26             this.bugApiKey = bugApiKey;
27             this.name = name;
28             this.bugDetailsURL = details;
29             connection = new BugConnection(name, url, bugApiKey, details);
30         }
31
32         public function load():void {
33             connection.loadBbox(map.edge_l, map.edge_r, map.edge_t, map.edge_b);
34             // FIXME Note this fires too early, since loadBbox is asynchronous
35             layer.updateEntityUIs(true, false);
36         }
37
38         private function get layer():MapPaint {
39             if (!_layer) {
40                 // should be done by the connection
41                 var policyFile:String = bugBaseURL+"crossdomain.xml";
42                 Security.loadPolicyFile(policyFile);
43
44                 _layer = map.addLayer(connection, STYLESHEET);
45             }
46             return _layer;
47         }
48     }
49 }