Refactor BugLayer to extend connection, and rename it to BugConnection to save confusion
authorAndy Allan <andy@gravitystorm.co.uk>
Mon, 23 May 2011 15:30:25 +0000 (16:30 +0100)
committerAndy Allan <andy@gravitystorm.co.uk>
Mon, 23 May 2011 15:30:25 +0000 (16:30 +0100)
net/systemeD/potlatch2/BugConnection.as [moved from net/systemeD/potlatch2/BugLayer.as with 92% similarity]
net/systemeD/potlatch2/TagViewer.mxml
net/systemeD/potlatch2/collections/VectorBackgrounds.as
net/systemeD/potlatch2/panels/BugPanel.mxml
net/systemeD/potlatch2/utils/BugLoader.as

similarity index 92%
rename from net/systemeD/potlatch2/BugLayer.as
rename to net/systemeD/potlatch2/BugConnection.as
index df6681c..006e5b9 100644 (file)
@@ -11,7 +11,7 @@ package net.systemeD.potlatch2 {
     /** A VectorLayer that can be used to load and display bugs from MapDust-compatible APIs.
         See utils/BugLoader.as for the corresponding loader. */
 
-    public class BugLayer extends VectorLayer {
+    public class BugConnection extends Connection {
 
         private var baseUrl:String;
         private var apiKey:String;
@@ -31,11 +31,11 @@ package net.systemeD.potlatch2 {
         public static var BUG_STATUS_INVALID:String = "3"; // or 'non-reproduceable'
         public static const status:Array = ["", "open", "fixed", "invalid"];
 
-        public function BugLayer(n:String, map:Map, s:String, baseUrl:String, apiKey:String, detailsURL:String) {
+        public function BugConnection(n:String, baseUrl:String, apiKey:String, detailsURL:String) {
             this.baseUrl = baseUrl;
             this.apiKey = apiKey;
             this.detailsUrl = detailsURL;
-            super(n,map,s);
+            super(n, baseUrl, null, null);
         }
 
         public function closeBug(m:Marker, nickname:String, comment:String, status:String = null):void {
@@ -67,7 +67,7 @@ package net.systemeD.potlatch2 {
         public override function loadBbox(left:Number, right:Number,
                                 top:Number, bottom:Number):void {
             var loader:URLLoader = new URLLoader();
-            loader.load(new URLRequest(baseUrl+"getBugs?bbox="+map.edge_l+","+map.edge_b+","+map.edge_r+","+map.edge_t+"&key="+apiKey+"&filter_status="+filter_status+"&filter_type="+filter_type+commentType));
+            loader.load(new URLRequest(baseUrl+"getBugs?bbox="+left+","+bottom+","+right+","+top+"&key="+apiKey+"&filter_status="+filter_status+"&filter_type="+filter_type+commentType));
             loader.addEventListener(Event.COMPLETE, parseJSON);
             loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleError);
             loader.addEventListener(IOErrorEvent.IO_ERROR, handleError);
@@ -97,7 +97,6 @@ package net.systemeD.potlatch2 {
                 tags["status"] = status[int(feature.properties.status)];
                 var marker:Marker = createMarker(tags, lat, lon, Number(feature.id));
               }
-              paint.updateEntityUIs(true, false);
             }
         }
 
index eb9b636..915cebc 100644 (file)
                        if (selectedEntity!=null) { selectedEntity.addEventListener(Connection.TAG_CHANGED, tagChanged); }
                        if (advancedID!=null) { setupAdvanced(firstSelected); }
                        if (firstSelected is Relation) { stack.addChild(membersVBox); }
-            if (selectedEntity is Marker && layer is BugLayer) {
-              bugPanelContents.init(selectedEntity, layer);
+            if (selectedEntity is Marker && connection is BugConnection) {
+              bugPanelContents.init(selectedEntity, BugConnection(connection));
               sidebar.selectedChild = bugPanel;
             } else if (selectedEntity is Marker) {
               markerPanelContents.init(selectedEntity, layer);
index b84f895..1ced4e3 100644 (file)
@@ -44,19 +44,19 @@ package net.systemeD.potlatch2.collections {
                 case "KMLImporter":
                   break;
                 case "GPXImporter":
-                  if (set.url) {
-                    if (set.@loaded == "true") {
-                      name ||= 'GPX file';
-                                         // >>>> REFACTOR: VectorLayer commented out
-                      // var layer:VectorLayer = new VectorLayer(name, _map, 'stylesheets/gpx.css');
-                      // _map.addVectorLayer(layer);
-                      // var gpxImporter:GpxImporter = new GpxImporter(layer, layer.paint, [String(set.url)]);
-                    } else {
-                      trace("configured but not loaded isn't supported yet");
-                    }
-                  } else {
-                    trace("AutoVectorBackground: no url for GPXImporter");
-                  }
+//                   if (set.url) {
+//                     if (set.@loaded == "true") {
+//                       name ||= 'GPX file';
+//                                       // >>>> REFACTOR: VectorLayer commented out
+//                       // var layer:VectorLayer = new VectorLayer(name, _map, 'stylesheets/gpx.css');
+//                       // _map.addVectorLayer(layer);
+//                       // var gpxImporter:GpxImporter = new GpxImporter(layer, layer.paint, [String(set.url)]);
+//                     } else {
+//                       trace("configured but not loaded isn't supported yet");
+//                     }
+//                   } else {
+//                     trace("AutoVectorBackground: no url for GPXImporter");
+//                   }
                   break;
 
                 case "BugLoader":
index b5237ce..6e3d96a 100644 (file)
 
       import net.systemeD.halcyon.connection.*;
       import net.systemeD.halcyon.VectorLayer;
-      import net.systemeD.potlatch2.BugLayer;
+      import net.systemeD.potlatch2.BugConnection;
       import mx.collections.*;
       import com.adobe.utils.DateUtil;
 
       private var selectedEntity:Entity;
-      private var layer:VectorLayer;
+      private var connection:BugConnection;
 
       [Bindable] private var bugId:String;
       [Bindable] private var bugStatus:String;
@@ -77,8 +77,8 @@
       [Bindable] private var bugUpdated:Date;
       [Bindable] private var bugDetails:String;
 
-      public function init(entity:Entity, layer:VectorLayer):void {
-            this.layer = layer;
+      public function init(entity:Entity, connection:BugConnection):void {
+            this.connection = connection;
             selectedEntity=entity;
 
             bugId = selectedEntity.getTag("bug_id");
             bugCreated = DateUtil.parseW3CDTF(selectedEntity.getTag("date_created"));
             bugUpdated = DateUtil.parseW3CDTF(selectedEntity.getTag("date_updated"));
 
-            if ( bugStatus == BugLayer.status[int(BugLayer.BUG_STATUS_FIXED)] ) {
+            if ( bugStatus == BugConnection.status[int(BugConnection.BUG_STATUS_FIXED)] ) {
               bugControlStack.selectedChild = bugFixed;
-            } else if ( bugStatus == BugLayer.status[int(BugLayer.BUG_STATUS_INVALID)] ) {
+            } else if ( bugStatus == BugConnection.status[int(BugConnection.BUG_STATUS_INVALID)] ) {
               bugControlStack.selectedChild = bugInvalid;
             } else {
               bugControlStack.selectedChild = bugControl;
             }
 
-            var u:String = BugLayer(layer).bugDetailsUrl(Marker(selectedEntity));
+            var u:String = connection.bugDetailsUrl(Marker(selectedEntity));
             if (u) {
               bugDetails = u;
               bugDetailsHbox.visible=true;
       }
 
       private function closeBug():void {
-            var status:String = option_invalid.selected ? BugLayer.BUG_STATUS_INVALID : BugLayer.BUG_STATUS_FIXED;
+            var status:String = option_invalid.selected ? BugConnection.BUG_STATUS_INVALID : BugConnection.BUG_STATUS_FIXED;
             trace(status);
-            BugLayer(layer).closeBug(selectedEntity as Marker, nickName.text, closeComment.text, status);
+            connection.closeBug(selectedEntity as Marker, nickName.text, closeComment.text, status);
             bugStatus = selectedEntity.getTag("status");
             // this should really be a 'saving...' state, with a callback depending on the server result
             bugControlStack.selectedChild = option_invalid.selected ? bugInvalid : bugFixed;
index 5b70251..34ca32a 100644 (file)
@@ -1,9 +1,9 @@
 package net.systemeD.potlatch2.utils {
 
     import net.systemeD.halcyon.Map;
-    import net.systemeD.halcyon.VectorLayer;
+    import net.systemeD.halcyon.MapPaint;
     import net.systemeD.halcyon.connection.Marker;
-    import net.systemeD.potlatch2.BugLayer;
+    import net.systemeD.potlatch2.BugConnection;
     import flash.net.*;
     import flash.events.*;
     import flash.system.Security;
@@ -14,9 +14,10 @@ package net.systemeD.potlatch2.utils {
         private var bugBaseURL:String;
         private var bugApiKey:String;
         private var bugDetailsURL:String;
-        private var _layer:VectorLayer;
+        private var _layer:MapPaint;
         private var name:String;
         private static const STYLESHEET:String="stylesheets/bugs.css";
+        private var connection:BugConnection;
 
 
         public function BugLoader(map:Map, url:String, bugApiKey:String, name:String, details:String = ''):void {
@@ -25,23 +26,24 @@ package net.systemeD.potlatch2.utils {
             this.bugApiKey = bugApiKey;
             this.name = name;
             this.bugDetailsURL = details;
+            connection = new BugConnection(name, url, bugApiKey, details);
         }
 
         public function load():void {
-            layer.loadBbox(map.edge_l, map.edge_r, map.edge_t, map.edge_b);
+            connection.loadBbox(map.edge_l, map.edge_r, map.edge_t, map.edge_b);
+            // FIXME Note this fires too early, since loadBbox is asynchronous
+            layer.updateEntityUIs(true, false);
         }
 
+        private function get layer():MapPaint {
+            if (!_layer) {
+                // should be done by the connection
+                var policyFile:String = bugBaseURL+"crossdomain.xml";
+                Security.loadPolicyFile(policyFile);
 
-        private function get layer():VectorLayer {
-                       // >>>> REFACTOR: VectorLayer commented out
-            // if (!_layer) {
-            //     var policyFile:String = bugBaseURL+"crossdomain.xml";
-            //     Security.loadPolicyFile(policyFile);
-            //     _layer=new BugLayer(name,map,STYLESHEET,bugBaseURL,bugApiKey,bugDetailsURL);
-            //     map.addVectorLayer(_layer);
-            // }
-            // return _layer;
-                       return null;
+                _layer = map.addLayer(connection, STYLESHEET);
+            }
+            return _layer;
         }
     }
 }
\ No newline at end of file