From ea3a233b39125a0b6e7ac954f03e29235f1d81bf Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Mon, 23 May 2011 16:30:25 +0100 Subject: [PATCH] Refactor BugLayer to extend connection, and rename it to BugConnection to save confusion --- .../{BugLayer.as => BugConnection.as} | 9 +++--- net/systemeD/potlatch2/TagViewer.mxml | 4 +-- .../collections/VectorBackgrounds.as | 26 ++++++++-------- net/systemeD/potlatch2/panels/BugPanel.mxml | 18 +++++------ net/systemeD/potlatch2/utils/BugLoader.as | 30 ++++++++++--------- 5 files changed, 44 insertions(+), 43 deletions(-) rename net/systemeD/potlatch2/{BugLayer.as => BugConnection.as} (92%) diff --git a/net/systemeD/potlatch2/BugLayer.as b/net/systemeD/potlatch2/BugConnection.as similarity index 92% rename from net/systemeD/potlatch2/BugLayer.as rename to net/systemeD/potlatch2/BugConnection.as index df6681c6..006e5b9c 100644 --- a/net/systemeD/potlatch2/BugLayer.as +++ b/net/systemeD/potlatch2/BugConnection.as @@ -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); } } diff --git a/net/systemeD/potlatch2/TagViewer.mxml b/net/systemeD/potlatch2/TagViewer.mxml index eb9b636b..915cebc7 100644 --- a/net/systemeD/potlatch2/TagViewer.mxml +++ b/net/systemeD/potlatch2/TagViewer.mxml @@ -265,8 +265,8 @@ 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); diff --git a/net/systemeD/potlatch2/collections/VectorBackgrounds.as b/net/systemeD/potlatch2/collections/VectorBackgrounds.as index b84f8956..1ced4e35 100644 --- a/net/systemeD/potlatch2/collections/VectorBackgrounds.as +++ b/net/systemeD/potlatch2/collections/VectorBackgrounds.as @@ -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": diff --git a/net/systemeD/potlatch2/panels/BugPanel.mxml b/net/systemeD/potlatch2/panels/BugPanel.mxml index b5237ce5..6e3d96ad 100644 --- a/net/systemeD/potlatch2/panels/BugPanel.mxml +++ b/net/systemeD/potlatch2/panels/BugPanel.mxml @@ -60,12 +60,12 @@ 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"); @@ -90,15 +90,15 @@ 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; @@ -106,9 +106,9 @@ } 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; diff --git a/net/systemeD/potlatch2/utils/BugLoader.as b/net/systemeD/potlatch2/utils/BugLoader.as index 5b70251f..34ca32a8 100644 --- a/net/systemeD/potlatch2/utils/BugLoader.as +++ b/net/systemeD/potlatch2/utils/BugLoader.as @@ -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 -- 2.36.1