1 package net.systemeD.potlatch2.utils {
3 import net.systemeD.halcyon.Map;
4 import net.systemeD.halcyon.VectorLayer;
5 import net.systemeD.halcyon.connection.Marker;
6 import net.systemeD.potlatch2.BugLayer;
9 import com.adobe.serialization.json.JSON;
10 import flash.system.Security;
12 public class BugLoader {
15 private var bugBaseURL:String;
16 private var bugApiKey:String;
17 private var _layer:VectorLayer;
18 private static const STYLESHEET:String="bugs.css";
19 private static const status:Array = ["", "open", "fixed", "invalid"];
21 public function BugLoader(map:Map, url:String, bugApiKey:String):void {
23 this.bugBaseURL = url;
24 this.bugApiKey = bugApiKey;
25 var policyFile:String = bugBaseURL+"crossdomain.xml";
26 Security.loadPolicyFile(policyFile);
29 public function load():void {
30 var loader:URLLoader = new URLLoader();
31 loader.load(new URLRequest(bugBaseURL+"getBugs?bbox="+map.edge_l+","+map.edge_b+","+map.edge_r+","+map.edge_t+"&key="+bugApiKey));
32 loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, balls);
33 loader.addEventListener(Event.COMPLETE, parseJSON);
36 public function balls(event:SecurityErrorEvent):void {
40 private function parseJSON(event:Event):void {
41 var result:String = String(event.target.data);
42 var featureCollection:Object = JSON.decode(result);
44 for each (var feature:Object in featureCollection.features) {
45 // geoJSON spec is x,y,z i.e. lon, lat, ele
46 var lon:Number = feature.geometry.coordinates[0];
47 var lat:Number = feature.geometry.coordinates[1];
49 tags["name"] = String(feature.properties.description).substr(0,10)+'...';
50 tags["description"] = feature.properties.description;
51 tags["bug_id"] = feature.id;
52 tags["nickname"] = feature.properties.nickname;
53 tags["type"] = feature.properties.type;
54 tags["date_created"] = feature.properties.date_created;
55 tags["date_updated"] = feature.properties.date_updated;
56 tags["source"] = feature.properties.source;
57 tags["status"] = status[int(feature.properties.status)];
58 var marker:Marker = layer.createMarker(tags, lat, lon);
60 layer.paint.updateEntityUIs(layer.getObjectsByBbox(map.edge_l,map.edge_r,map.edge_t,map.edge_b), true, false);
63 private function get layer():VectorLayer {
66 _layer=new BugLayer(n,map,STYLESHEET,bugBaseURL,bugApiKey);
67 map.addVectorLayer(_layer);