Refactoring in progress
authorRichard Fairhurst <richard@systemeD.net>
Sat, 21 May 2011 11:52:54 +0000 (12:52 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sat, 21 May 2011 11:52:54 +0000 (12:52 +0100)
21 files changed:
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/MapPaint.as
net/systemeD/halcyon/VectorLayer.as
net/systemeD/halcyon/connection/AMFConnection.as
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/OSMConnection.as
net/systemeD/halcyon/connection/Trace.as
net/systemeD/halcyon/connection/UndoableEntityAction.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/potlatch2/BugLayer.as
net/systemeD/potlatch2/RelationLoaderPanel.mxml
net/systemeD/potlatch2/RelationSelectPanel.mxml
net/systemeD/potlatch2/TagViewer.mxml
net/systemeD/potlatch2/mapfeatures/editors/TurnRestrictionEditor.mxml
net/systemeD/potlatch2/mygpx/MyGpxDialog.mxml
net/systemeD/potlatch2/save/OAuthPanel.mxml
net/systemeD/potlatch2/save/SaveDialog.mxml
net/systemeD/potlatch2/save/SaveManager.as
net/systemeD/potlatch2/utils/BikeShopLoader.as
net/systemeD/potlatch2/utils/Importer.as
net/systemeD/potlatch2/utils/TrackLoader.as

index ffc920a02d63f6c2d8d235a03711ec4cdd840e66..5024b23e9fa4d979ab7897ec6aee29cdb39e93a2 100644 (file)
@@ -28,10 +28,8 @@ package net.systemeD.halcyon {
                /** don't zoom in past this */
                public const MAXSCALE:uint=23; 
 
-               /** sprite for ways and (POI/tagged) nodes in core layer */
-               public var paint:MapPaint;                                               
-               /** sprite for vector background layers */
-               public var vectorbg:Sprite;
+               // Container for MapPaint objects
+               public var paintContainer:Sprite;
 
                /** map scale */
                public var scale:uint=14;                                                
@@ -69,7 +67,7 @@ package net.systemeD.halcyon {
                /** How far the map can be dragged without actually triggering a pan. */
                public const TOLERANCE:uint=7;                                  //  |
                
-               /** object containing HTML page parameters */
+               /** object containing HTML page parameters: lat, lon, zoom, background_dim, background_sharpen, tileblocks */
                public var initparams:Object; 
 
                /** reference to backdrop sprite */
@@ -83,92 +81,44 @@ package net.systemeD.halcyon {
                /** show all objects, even if unstyled? */
                public var showall:Boolean=true; 
                
-               /** server connection */
-               public var connection:Connection; 
-               /** VectorLayer objects */
-               public var vectorlayers:Object={};  
-               
                // ------------------------------------------------------------------------------------------
                /** Map constructor function */
-        public function Map(initparams:Object) {
+        public function Map() {
+                       // Remove any existing sprites
+                       while (numChildren) { removeChildAt(0); }
+
+                       // 900913 background
+                       tileset=new TileSet(this);
+                       addChild(tileset);
 
-                       this.initparams=initparams;
-                       connection = Connection.getConnection(initparams);
-            connection.addEventListener(Connection.NEW_WAY, newWayCreated);
-            connection.addEventListener(Connection.NEW_POI, newPOICreated);
-            connection.addEventListener(Connection.WAY_RENUMBERED, wayRenumbered);
-            connection.addEventListener(Connection.NODE_RENUMBERED, nodeRenumbered);
-                       gotEnvironment(null);
+                       // Container for all MapPaint objects
+                       paintContainer = new Sprite();
+                       addChild(paintContainer);
 
                        addEventListener(Event.ENTER_FRAME, everyFrame);
                        scrollRect=new Rectangle(0,0,800,600);
-        }
 
-               public function gotEnvironment(r:Object):void {
-                       var loader:Loader = new Loader();
-                       loader.contentLoaderInfo.addEventListener(Event.COMPLETE, gotFont);
-                       loader.load(new URLRequest("FontLibrary.swf"));
-               }
-               
-               public function gotFont(r:Event):void {
-                       var FontLibrary:Class = r.target.applicationDomain.getDefinition("FontLibrary") as Class;
-                       Font.registerFont(FontLibrary.DejaVu);
-
-                       if (initparams['lat'] != null) {
-                               // parameters sent from HTML
-                               init(initparams['lat'],
-                                        initparams['lon'],
-                                        initparams['zoom']);
-
-                       } else {
-                               // somewhere innocuous
-                               init(53.09465,-2.56495,17);
+                       if (ExternalInterface.available) {
+                               ExternalInterface.addCallback("setPosition", function (lat:Number,lon:Number,zoom:uint):void {
+                                       updateCoordsFromLatLon(lat, lon);
+                                       changeScale(zoom);
+                               });
                        }
                }
 
                // ------------------------------------------------------------------------------------------
                /** Initialise map at a given lat/lon */
         public function init(startlat:Number, startlon:Number, startscale:uint=0):void {
-                       while (numChildren) { removeChildAt(0); }
-
-                       tileset=new TileSet(this);                                      // 0 - 900913 background
-                       if (initparams['tileblocks']) {                         //   | option to block dodgy tile sources
-                               tileset.blocks=initparams['tileblocks'];//   |
-                       }                                                                                       //   |
-                       addChild(tileset);                                                      //   |
-                       tileset.init(tileparams, false, 
-                                    initparams['background_dim']    ==null ? true  : initparams['background_dim'],
-                                    initparams['background_sharpen']==null ? false : initparams['background_sharpen']);
-
-                       vectorbg = new Sprite();                                        // 1 - vector background layers
-                       addChild(vectorbg);                                                     //   |
-
-                       paint = new MapPaint(this,-5,5);                        // 2 - core paint object
-                       addChild(paint);                                                        //   |
-                       paint.isBackground=false;                                       //   |
-
-                       if (styleurl) {                                                         // if we've only just set up paint, then setStyle won't have created the RuleSet
-                               paint.ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
-                               paint.ruleset.loadFromCSS(styleurl);
-                       }
                        if (startscale>0) {
                                scale=startscale;
                                this.dispatchEvent(new MapEvent(MapEvent.SCALE, {scale:scale}));
                        }
-
                        scalefactor=MASTERSCALE/Math.pow(2,13-scale);
                        baselon    =startlon          -(mapwidth /2)/scalefactor;
                        basey      =lat2latp(startlat)+(mapheight/2)/scalefactor;
                        updateCoords(0,0);
             this.dispatchEvent(new Event(MapEvent.INITIALISED));
                        download();
-
-            if (ExternalInterface.available) {
-              ExternalInterface.addCallback("setPosition", function (lat:Number,lon:Number,zoom:uint):void {
-                  updateCoordsFromLatLon(lat, lon);
-                  changeScale(zoom);
-              });
-            }
         }
 
                // ------------------------------------------------------------------------------------------
@@ -220,14 +170,14 @@ package net.systemeD.halcyon {
 
                private function moveMap(dx:Number,dy:Number):void {
                        updateCoords(getX()+dx,getY()+dy);
-                       updateEntityUIs(false, false);
+                       updateAllEntityUIs(false, false);
                        download();
                }
                
                /** Recentre map at given lat/lon, updating the UI and downloading entities. */
                public function moveMapFromLatLon(lat:Number,lon:Number):void {
                        updateCoordsFromLatLon(lat,lon);
-                       updateEntityUIs(false,false);
+                       updateAllEntityUIs(false,false);
                        download();
                }
                
@@ -278,80 +228,19 @@ package net.systemeD.halcyon {
         */
                public function download():void {
                        this.dispatchEvent(new MapEvent(MapEvent.DOWNLOAD, {minlon:edge_l, maxlon:edge_r, maxlat:edge_t, minlat:edge_b} ));
-                       connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
-
-            // Do the same for vector layers
-            for each (var layer:VectorLayer in vectorlayers) {
-              layer.loadBbox(edge_l,edge_r,edge_t,edge_b);
-            }
-               }
-
-        private function newWayCreated(event:EntityEvent):void {
-            var way:Way = event.entity as Way;
-                       if (!way.loaded || !way.within(edge_l,edge_r,edge_t,edge_b)) { return; }
-                       paint.createWayUI(way);
-        }
-
-        private function newPOICreated(event:EntityEvent):void {
-            var node:Node = event.entity as Node;
-                       if (!node.within(edge_l,edge_r,edge_t,edge_b)) { return; }
-                       paint.createNodeUI(node);
-        }
-
-               private function wayRenumbered(event:EntityRenumberedEvent):void {
-            var way:Way = event.entity as Way;
-                       paint.renumberWayUI(way,event.oldID);
-               }
-
-               private function nodeRenumbered(event:EntityRenumberedEvent):void {
-            var node:Node = event.entity as Node;
-                       paint.renumberNodeUI(node,event.oldID);
+                       for (var i:uint=0; i<paintContainer.numChildren; i++) {
+                               paintContainer.getChildAt(i).connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
+                       }
                }
 
-        /** Visually mark an entity as highlighted. */
-        public function setHighlight(entity:Entity, settings:Object):void {
-                       if      ( entity is Way  && paint.wayuis[entity.id] ) { paint.wayuis[entity.id].setHighlight(settings);  }
-                       else if ( entity is Node && paint.nodeuis[entity.id]) { paint.nodeuis[entity.id].setHighlight(settings); }
-        }
-
-        public function setHighlightOnNodes(way:Way, settings:Object):void {
-                       if (paint.wayuis[way.id]) paint.wayuis[way.id].setHighlightOnNodes(settings);
-        }
+               // >>>> REFACTOR: moved to MapPaint:
+        // public function setHighlight(entity:Entity, settings:Object):void {
+        // public function setHighlightOnNodes(way:Way, settings:Object):void {
+               // public function protectWay(way:Way):void {
+               // public function unprotectWay(way:Way):void {
+               // public function limitWayDrawing(way:Way,except:Number=NaN,only:Number=NaN):void {
+               // public function setPurgable(entities:Array, purgable:Boolean):void {
 
-               public function protectWay(way:Way):void {
-                       if (paint.wayuis[way.id]) paint.wayuis[way.id].protectSprites();
-               }
-
-               public function unprotectWay(way:Way):void {
-                       if (paint.wayuis[way.id]) paint.wayuis[way.id].unprotectSprites();
-               }
-               
-               public function limitWayDrawing(way:Way,except:Number=NaN,only:Number=NaN):void {
-                       if (!paint.wayuis[way.id]) return;
-                       paint.wayuis[way.id].drawExcept=except;
-                       paint.wayuis[way.id].drawOnly  =only;
-                       paint.wayuis[way.id].redraw();
-               }
-
-               /** Protect Entities and EntityUIs against purging. This prevents the currently selected items
-                  from being purged even though they're off-screen. */
-
-               public function setPurgable(entities:Array, purgable:Boolean):void {
-                       for each (var entity:Entity in entities) {
-                               entity.locked=!purgable;
-                               if ( entity is Way  ) {
-                                       var way:Way=entity as Way;
-                                       if (paint.wayuis[way.id]) { paint.wayuis[way.id].purgable=purgable; }
-                                       for (var i:uint=0; i<way.length; i++) {
-                                               var node:Node=way.getNode(i)
-                                               node.locked=!purgable;
-                                               if (paint.nodeuis[node.id]) { paint.nodeuis[node.id].purgable=purgable; }
-                                       }
-                               } else if ( entity is Node && paint.nodeuis[entity.id]) { 
-                                       paint.nodeuis[entity.id].purgable=purgable;
-                               }
-                       }
-               }
 
         // Handle mouse events on ways/nodes
         private var mapController:MapController = null;
@@ -364,61 +253,59 @@ package net.systemeD.halcyon {
         public function entityMouseEvent(event:MouseEvent, entity:Entity):void {
             if ( mapController != null )
                 mapController.entityMouseEvent(event, entity);
-                               
         }
 
                // ------------------------------------------------------------------------------------------
-               // Add vector layer
+               // Add layers
                
-               public function addVectorLayer(layer:VectorLayer):void {
-                       vectorlayers[layer.name]=layer;
-                       vectorbg.addChild(layer.paint);
+               public function addLayer(connection:Connection, styleurl:String, backgroundlayer:Boolean=true):void {
+                       var paint:MapPaint=new MapPaint(this,connection,-5,5);
+                       paintContainer.addChild(paint);
+                       paint.isBackground=backgroundlayer;
+                       if (styleurl) {
+                               // if we've only just set up paint, then setStyle won't have created the RuleSet
+                               paint.ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
+                               paint.ruleset.loadFromCSS(styleurl);
+                       }
                }
-               
-               public function removeVectorLayer(layer:VectorLayer):void {
-                       if (!layer) return;
-                       layer.blank();
-                       vectorbg.removeChild(layer.paint);
-                       delete vectorlayers[layer.name];
+
+               public function removeLayerByName(name:String):void {
+                       for (var i:uint=0; i<paintContainer.numChildren; i++)
+                               if (paintContainer.getChildAt(i).connection.name==name) {
+                                       paintContainer.removeChildAt(i);
+                                       // >>>> REFACTOR: needs to do the equivalent of VectorLayer.blank()
+                               }
+                       }
                }
                
-               public function findVectorLayer(name:String):VectorLayer {
-                       for each (var layer:VectorLayer in vectorlayers) {
-                               if (layer.name==name) { return layer; }
-                       }
+               public function findLayer(name:String):MapPaint {
+                       for (var i:uint=0; i<paintContainer.numChildren; i++)
+                               if (paintContainer.getChildAt(i).connection.name==name) return paintContainer.getChildAt(i);
                        return null;
                }
 
                // ------------------------------------------------------------------------------------------
                // Redraw all items, zoom in and out
                
-               public function updateEntityUIs(redraw:Boolean,remove:Boolean):void {
-                       paint.updateEntityUIs(connection.getObjectsByBbox(edge_l, edge_r, edge_t, edge_b), redraw, remove);
-                       for each (var v:VectorLayer in vectorlayers) {
-                               v.paint.updateEntityUIs(v.getObjectsByBbox(edge_l, edge_r, edge_t, edge_b), redraw, remove);
-                       }
+               private function updateAllEntityUIs(redraw:Boolean,remove:Boolean):void {
+                       for (var i:uint=0; i<paintContainer.numChildren; i++)
+                               paintContainer.getChildAt(i).updateEntityUIs(redraw, remove);
                }
-               /** Redraw everything, including in every vector layer. */
                public function redraw():void {
-                       paint.redraw();
-                       for each (var v:VectorLayer in vectorlayers) { v.paint.redraw(); }
+                       for (var i:uint=0; i<paintContainer.numChildren; i++)
+                               paintContainer.getChildAt(i).redraw();
                }
-               /** Redraw POI's, including in every vector layer. */
                public function redrawPOIs():void { 
-                       paint.redrawPOIs();
-                       for each (var v:VectorLayer in vectorlayers) { v.paint.redrawPOIs(); }
+                       for (var i:uint=0; i<paintContainer.numChildren; i++)
+                               paintContainer.getChildAt(i).redrawPOIs();
                }
                
-               /** Increase scale. */
                public function zoomIn():void {
-                       if (scale==MAXSCALE) { return; }
-                       changeScale(scale+1);
+                       if (scale!=MAXSCALE) changeScale(scale+1);
                }
 
-               /** Decrease scale. */
                public function zoomOut():void {
-                       if (scale==MINSCALE) { return; }
-                       changeScale(scale-1);
+                       if (scale!=MINSCALE) changeScale(scale-1);
                }
 
                private function changeScale(newscale:uint):void {
@@ -427,7 +314,7 @@ package net.systemeD.halcyon {
                        scalefactor=MASTERSCALE/Math.pow(2,13-scale);
                        updateCoordsFromLatLon((edge_t+edge_b)/2,(edge_l+edge_r)/2);    // recentre
                        tileset.changeScale(scale);
-                       updateEntityUIs(true,true);
+                       updateAllEntityUIs(true,true);
                        download();
                }
 
index 91cac5c56616fb4b2e7aaaf59c72616b455cc54a..e3a90bc3a7fa9e746d0e78a133ccf4528aec0918 100644 (file)
@@ -10,11 +10,15 @@ package net.systemeD.halcyon {
        /** Manages the drawing of map entities, allocating their sprites etc. */
        public class MapPaint extends Sprite {
                
-               /** Access Map object */
+               /** Parent Map - required for finding out bounds and scale */
                public var map:Map;
-               /** Entities on layers below minlayer will not be shown by this paint object. (Confirm?) */
+
+               /** Source data for this MapPaint layer */
+               public var connection:Connection;
+
+               /** Lowest OSM layer that can be displayed */
                public var minlayer:int;
-               /** Entities on layers above maxlayer will not be shown by this paint object. (Confirm?) */
+               /** Highest OSM layer that can be displayed */
                public var maxlayer:int;
                /** The MapCSS rules used for drawing entities. */
                public var ruleset:RuleSet;                                             
@@ -40,19 +44,27 @@ package net.systemeD.halcyon {
                 * <p>Each paint sprite has 4 child sprites (fill, casing, stroke, names). Each hit sprite has 2 child sprites (way hit tests, node hit tests).</p>  
                 * <p>Thus if layers range from -5 to +5, there will be 11 top level paint sprites followed by 11 top level hit sprites.</p>
                 * 
-                * @param map The map to be rendered.
-                * @param minlayer The lowest layer in that map that will be rendered.
-                * @param maxlayer The top layer in that map that will be rendered.
+                * @param map The Map this is attached to. (Required for finding out bounds and scale.)
+                * @param connection The Connection containing the data for this layer.
+                * @param minlayer The lowest OSM layer to display.
+                * @param maxlayer The highest OSM layer to display.
                 * */ 
-               public function MapPaint(map:Map,minlayer:int,maxlayer:int) {
+               public function MapPaint(map:Map,connection:Connection,minlayer:int,maxlayer:int) {
                        mouseEnabled=false;
 
                        this.map=map;
+                       this.connection=connection;
                        this.minlayer=minlayer;
                        this.maxlayer=maxlayer;
                        sublayerIndex[1]=0;
                        var s:Sprite, l:int;
 
+                       // Listen for changes on this Connection
+            connection.addEventListener(Connection.NEW_WAY, newWayCreatedListener);
+            connection.addEventListener(Connection.NEW_POI, newPOICreatedListener);
+            connection.addEventListener(Connection.WAY_RENUMBERED, wayRenumberedListener);
+            connection.addEventListener(Connection.NODE_RENUMBERED, nodeRenumberedListener);
+
                        // Add paint sprites
                        for (l=minlayer; l<=maxlayer; l++) {                    // each layer (10 is +5, 0 is -5)
                                s = getPaintSprite();                                           //      |
@@ -135,21 +147,18 @@ package net.systemeD.halcyon {
                }
 
         /**
-        * Update, and if necessary, create / remove UIs for the given objects.
-        * The object is effectively lists of objects split into inside/outside pairs, e.g.
-        * { waysInside: [], waysOutside: [] } where each is a array of entities either inside
-        * or outside this current view window. UIs for the entities on "inside" lists will be created if necessary.
+        * Update, and if necessary, create / remove UIs for the current viewport.
         * Flags control redrawing existing entities and removing UIs from entities no longer in view.
         *
-        * @param o The object containing all the relevant entites.
         * @param redraw If true, all UIs for entities on "inside" lists will be redrawn
         * @param remove If true, all UIs for entites on "outside" lists will be removed. The purgable flag on UIs
                         can override this, for example for selected objects.
         * fixme? add smarter behaviour for way nodes - remove NodeUIs from way nodes off screen, create them for ones
         * that scroll onto screen (for highlights etc)
         */
-               public function updateEntityUIs(o:Object, redraw:Boolean, remove:Boolean):void {
+               public function updateEntityUIs(redraw:Boolean, remove:Boolean):void {
                        var way:Way, poi:Node, marker:Marker;
+                       var o:Object = connection.getObjectsByBbox(map.edge_l,map.edge_r,map.edge_t,map.edge_b);
 
                        for each (way in o.waysInside) {
                                if (!wayuis[way.id]) { createWayUI(way); }
@@ -326,6 +335,7 @@ package net.systemeD.halcyon {
             for each (var m:MarkerUI in markeruis) { m.invalidateStyleList(); m.redraw(); }
                }
                
+               // >>>> REFACTOR: remove this
                public function findSource():VectorLayer {
                        var v:VectorLayer;
                        for each (v in map.vectorlayers) {
@@ -333,5 +343,79 @@ package net.systemeD.halcyon {
                        }
                        return null;
                }
+
+               // ==================== Start of code moved from Map.as
+
+               // Listeners for Connection events
+
+        private function newWayCreatedListener(event:EntityEvent):void {
+            var way:Way = event.entity as Way;
+                       if (!way.loaded || !way.within(map.edge_l, map.edge_r, map.edge_t, map.edge_b)) { return; }
+                       createWayUI(way);
+        }
+
+        private function newPOICreatedListener(event:EntityEvent):void {
+            var node:Node = event.entity as Node;
+                       if (!node.within(map.edge_l, map.edge_r, map.edge_t, map.edge_b)) { return; }
+                       createNodeUI(node);
+        }
+
+               private function wayRenumberedListener(event:EntityRenumberedEvent):void {
+            var way:Way = event.entity as Way;
+                       renumberWayUI(way,event.oldID);
+               }
+
+               private function nodeRenumberedListener(event:EntityRenumberedEvent):void {
+            var node:Node = event.entity as Node;
+                       renumberNodeUI(node,event.oldID);
+               }
+
+        /** Visually mark an entity as highlighted. */
+        public function setHighlight(entity:Entity, settings:Object):void {
+                       if      ( entity is Way  && wayuis[entity.id] ) { wayuis[entity.id].setHighlight(settings);  }
+                       else if ( entity is Node && nodeuis[entity.id]) { nodeuis[entity.id].setHighlight(settings); }
+        }
+
+        public function setHighlightOnNodes(way:Way, settings:Object):void {
+                       if (wayuis[way.id]) wayuis[way.id].setHighlightOnNodes(settings);
+        }
+
+               public function protectWay(way:Way):void {
+                       if (wayuis[way.id]) wayuis[way.id].protectSprites();
+               }
+
+               public function unprotectWay(way:Way):void {
+                       if (wayuis[way.id]) wayuis[way.id].unprotectSprites();
+               }
+               
+               public function limitWayDrawing(way:Way,except:Number=NaN,only:Number=NaN):void {
+                       if (!wayuis[way.id]) return;
+                       wayuis[way.id].drawExcept=except;
+                       wayuis[way.id].drawOnly  =only;
+                       wayuis[way.id].redraw();
+               }
+
+               /** Protect Entities and EntityUIs against purging. This prevents the currently selected items
+                  from being purged even though they're off-screen. */
+
+               public function setPurgable(entities:Array, purgable:Boolean):void {
+                       for each (var entity:Entity in entities) {
+                               entity.locked=!purgable;
+                               if ( entity is Way  ) {
+                                       var way:Way=entity as Way;
+                                       if (wayuis[way.id]) { wayuis[way.id].purgable=purgable; }
+                                       for (var i:uint=0; i<way.length; i++) {
+                                               var node:Node=way.getNode(i)
+                                               node.locked=!purgable;
+                                               if (nodeuis[node.id]) { nodeuis[node.id].purgable=purgable; }
+                                       }
+                               } else if ( entity is Node && nodeuis[entity.id]) { 
+                                       nodeuis[entity.id].purgable=purgable;
+                               }
+                       }
+               }
+
+               // ==================== End of code moved from Map.as
+
        }
 }
index 9903988751357982e1d65fa23c71c93cdc4f7673..dfb64490bd6409503d633d4a786ce3f47b584750 100644 (file)
@@ -49,7 +49,7 @@ package net.systemeD.halcyon {
         /** Create a new node on the vector layer. Note that the node won't show up until on the map
         * until the the relevant nodeUI is created, so you will need to instruct the paint to create one
         *
-        * e.g. <code>layer.paint.updateEntityUIs(layer.getObjectsByBbox(...)...);</code>
+        * e.g. <code>layer.paint.updateEntityUIs(...);</code>
         */
                public function createNode(tags:Object,lat:Number,lon:Number):Node {
                        var node:Node = new Node(negativeID, 0, tags, true, lat, lon);
index 37d243d15db60edf0d2032810e2656ff87a603db..c47ec6d18dc4540a2fd3627e4dfd6e0e1e39911b 100644 (file)
@@ -25,8 +25,9 @@ package net.systemeD.halcyon.connection {
                // ------------------------------------------------------------
                // Constructor for new AMFConnection
 
-               public function AMFConnection() {
+               public function AMFConnection(name:String,api:String,policy:String,initparams:Object) {
 
+                       super(name,api,policy,initparams);
                        if (Connection.policyURL!='')
                 Security.loadPolicyFile(Connection.policyURL);
 
index 74514eb2dd596b1a42cce0d83bdf07beb2752f80..36933f9f4304a5b2fcde19f704d9f40ed67d8491 100644 (file)
@@ -10,31 +10,19 @@ package net.systemeD.halcyon.connection {
 
        public class Connection extends EventDispatcher {
 
-        private static var connectionInstance:Connection = null;
-
-        protected static var policyURL:String;
-        protected static var apiBaseURL:String;
-        protected static var params:Object;
-
-        public static function getConnection(initparams:Object=null):Connection {
-            if ( connectionInstance == null ) {
-            
-                params = initparams == null ? new Object() : initparams;
-                policyURL = getParam("policy", "http://127.0.0.1:3000/api/crossdomain.xml");
-                apiBaseURL = getParam("api", "http://127.0.0.1:3000/api/0.6/");
-                var connectType:String = getParam("connection", "XML");
-                
-                if ( connectType == "XML" )
-                    connectionInstance = new XMLConnection();
-                else if ( connectType == "OSM" )
-                    connectionInstance = new OSMConnection();
-                else
-                    connectionInstance = new AMFConnection();
-            }
-            return connectionInstance;
-        }
+               public var name:String;
+        protected var apiBaseURL:String;
+        protected var policyURL:String;
+        protected var params:Object;
 
-        public static function getParam(name:String, defaultValue:String):String {
+               public function Connection(cname:String,api:String,policy:String,initparams:Object={}) {
+                       name=cname;
+                       apiBaseURL=api;
+                       policyURL=policy;
+                       params=initparams;
+               }
+
+        public function getParam(name:String, defaultValue:String):String {
             return params[name] == null ? defaultValue : params[name];
         }
 
@@ -42,13 +30,9 @@ package net.systemeD.halcyon.connection {
             return apiBaseURL;
         }
 
-        public static function get serverName():String {
+        public function get serverName():String {
             return getParam("serverName", "Localhost");
         }
-                
-               public static function getConnectionInstance():Connection {
-            return connectionInstance;
-               }
 
                public function getEnvironment(responder:Responder):void {}
 
index 18f12944b373366b95d82c6a87bc50fa8123a370..794e96dbf50348d6aba5de40108e53b5d575c21c 100644 (file)
@@ -44,8 +44,9 @@ package net.systemeD.halcyon.connection {
 
                private static const FILENAME:RegExp=/([\-\d\.]+)_([\-\d\.]+)_([\-\d\.]+)_([\-\d\.]+)\./i;
 
-               public function OSMConnection() {
+               public function OSMConnection(name:String,api:String,policy:String,initparams:Object) {
 
+                       super(name,api,policy,initparams);
                        if (Connection.policyURL!='')
                 Security.loadPolicyFile(Connection.policyURL);
 
index 5c4402fd0b2de1b2d44d3b13c331346ad199f6f1..17bb5725b8a2a121d222beda149b5013c4a704a2 100644 (file)
@@ -61,7 +61,7 @@ package net.systemeD.halcyon.connection {
 
         private function fetchFromServer():void {
             // todo - needs proper error handling
-            Connection.getConnectionInstance().fetchTrace(id, saveTraceData);
+            Connection.getConnection().fetchTrace(id, saveTraceData);
             dispatchEvent(new Event("loading_data"));
         }
 
@@ -129,7 +129,7 @@ package net.systemeD.halcyon.connection {
             }
 
                        default xml namespace = new Namespace("");
-            layer.paint.updateEntityUIs(layer.getObjectsByBbox(map.edge_l,map.edge_r,map.edge_t,map.edge_b), true, false);
+            layer.paint.updateEntityUIs(true, false);
         }
     }
 }
index b72c58b7f37aca916a2d5169bcb8529256d542cf..c8f5f32a3cdb10b95d305ac509818777bcb78d56 100644 (file)
@@ -36,7 +36,7 @@ package net.systemeD.halcyon.connection {
             }
 
             if ( !connectionWasDirty ) {
-              Connection.getConnectionInstance().markDirty();
+              Connection.getConnection().markDirty();
             }
         }
 
@@ -52,7 +52,7 @@ package net.systemeD.halcyon.connection {
             }
 
             if ( !connectionWasDirty ) {
-              Connection.getConnectionInstance().markClean();
+              Connection.getConnection().markClean();
             }
         }
 
@@ -62,7 +62,7 @@ package net.systemeD.halcyon.connection {
         */
         private function init():void {
             wasDirty = entity.isDirty;
-            connectionWasDirty = Connection.getConnectionInstance().isDirty;
+            connectionWasDirty = Connection.getConnection().isDirty;
             initialised = true;
         }
             
index b77d59d37439b44bc326f4c434ec632546292d39..3ce5505997a41062731bbf0beafe15cf4e8e7517 100644 (file)
@@ -16,8 +16,9 @@ package net.systemeD.halcyon.connection {
     */
        public class XMLConnection extends XMLBaseConnection {
 
-               public function XMLConnection() {
+               public function XMLConnection(name:String,api:String,policy:String,initparams:Object) {
 
+                       super(name,api,policy,initparams);
                        if (Connection.policyURL!='')
                 Security.loadPolicyFile(Connection.policyURL);
             var oauthPolicy:String = Connection.getParam("oauth_policy", "");
index 4a1c7ce1ca6fd7ae53ec79f5ae61e5a91375423f..df6681c6b3adddf359c2f3985964f4652e6c3a71 100644 (file)
@@ -97,7 +97,7 @@ package net.systemeD.potlatch2 {
                 tags["status"] = status[int(feature.properties.status)];
                 var marker:Marker = createMarker(tags, lat, lon, Number(feature.id));
               }
-              paint.updateEntityUIs(getObjectsByBbox(map.edge_l,map.edge_r,map.edge_t,map.edge_b), true, false);
+              paint.updateEntityUIs(true, false);
             }
         }
 
index 53c9624ee694b42d42d7d322c3b18b0325a48b51..39fb79fa94b3fe21e7fd2af7762136ca19f9cab1 100644 (file)
@@ -31,7 +31,7 @@
                        relid = Number(requestedID.text);
                        PopUpManager.removePopUp(this);
 
-                       var conn:Connection = Connection.getConnectionInstance();
+                       var conn:Connection = Connection.getConnection();
                        if (!relid) return;
                        if (conn.getRelation(relid)) {
                                relationLoaded(null);
@@ -42,7 +42,7 @@
                }
                
                private function relationLoaded(event:Event):void {
-                       var conn:Connection = Connection.getConnectionInstance();
+                       var conn:Connection = Connection.getConnection();
                        var relation:Relation = conn.getRelation(relid);
                        conn.removeEventListener(Connection.LOAD_COMPLETED, relationLoaded);
                        if (!relation) return;
index 6cd409ed007ff423060976e410bdab72aa1bbed0..3c17eaff647b3952a5535003a1295f9a88b944aa 100644 (file)
@@ -32,7 +32,7 @@
           PopUpManager.centerPopUp(this);
     
           var titles:Array = [];
-          conn = Connection.getConnectionInstance();
+          conn = Connection.getConnection();
           relationList = conn.getMatchingRelationIDs(t);
           if (relationList.length == 0) {
             warning.text = "No relations available";
index a6f961b29cd4eef36b9492973857dc5e24a0130f..582d9212cda4ffd7997d92fc77ef9a8646df8a84 100644 (file)
           // but is at least robust for any kind of change.
           // Figuring out a better way is someone else's FIXME
 
-          var conn:Connection = Connection.getConnectionInstance();
+          var conn:Connection = Connection.getConnection();
           var rel:Relation = selectedEntity as Relation
           var action:CompositeUndoableAction = new CompositeUndoableAction("Rearrange relation members for "+rel);
 
       private function editRelation(id:Number):void {
           var panel:RelationEditorPanel = RelationEditorPanel(
               PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
-          panel.setRelation(Connection.getConnectionInstance().getRelation(id));
+          panel.setRelation(Connection.getConnection().getRelation(id));
           PopUpManager.centerPopUp(panel);
       }
 
       public function openEntityPage():void {
           if (selectedEntity != null && selectedEntity.id >= 0) {
               // This is slightly hard-coded, but not drastically. The ../s could be changed for string manipulation of the apiBase
-              var urlBase:String = Connection.getConnectionInstance().apiBase + '../../browse/'
+              var urlBase:String = Connection.getConnection().apiBase + '../../browse/'
               navigateToURL(new URLRequest(urlBase+selectedEntity.getType()+'/'+selectedEntity.id), "potlatch_browse");
           }
       }
       }
 
       private function removeFromRelation(id:Number, index:int=-1):void {
-               var rel:Relation=Connection.getConnectionInstance().getRelation(id);
+               var rel:Relation=Connection.getConnection().getRelation(id);
                if (index>-1) {
                        rel.removeMemberByIndex(index, MainUndoStack.getGlobalStack().addAction);
                } else if (selectedEntity is EntityCollection) {
index c5ee509136aa972eb110ad511f63c721f7744381..852c4b9488eee6e2eb12e9cd76902a1e3c4fb1e8 100644 (file)
@@ -30,7 +30,7 @@
        }
 
        public function addNewTurnRestriction():void {
-               var conn:Connection = Connection.getConnectionInstance();
+               var conn:Connection = Connection.getConnection();
                var relation:Relation = conn.createRelation(
                        { type: 'restriction' }, 
                        [ new RelationMember(_entity, 'via') ],
index 238815c764cf22de49e8d1ab2eda70918639db41..3ca3c5c8e4447a789a8867d16ad89ce5186708b4 100644 (file)
@@ -27,7 +27,7 @@
         PopUpManager.centerPopUp(this);
         this.addEventListener(CloseEvent.CLOSE, myGpxDialog_close);
 
-        conn = Connection.getConnectionInstance();
+        conn = Connection.getConnection();
         map = Globals.vars.root;
 
         conn.addEventListener(Connection.TRACES_LOADED, onTracesLoaded);
index bada911a19254f2bcab3e3217c85d75c6b81148d..350df9be9337b254c5657f1cfa0c056d8b0ce235 100644 (file)
                }
         
         private function getRequestToken():void {
-            connection = Connection.getConnectionInstance();
+            connection = Connection.getConnection();
             
             var sig:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
             var consumer:OAuthConsumer = getConsumer();
             PopUpManager.removePopUp(this);
             
             _accessToken = getResponseToken(URLLoader(event.target));
-            Connection.getConnectionInstance().setAuthToken(_accessToken);
+            Connection.getConnection().setAuthToken(_accessToken);
             dispatchEvent(new Event(ACCESS_TOKEN_EVENT));
         }
         
index 9d121a2691cb1c834dab08fd7d960259156a6e1c..ae3e60f633c34be60d69d9a7c8e785f852e86855 100644 (file)
@@ -83,7 +83,7 @@
     import net.systemeD.halcyon.connection.*;
     import net.systemeD.halcyon.AttentionEvent;
     
-    private var conn:Connection = Connection.getConnectionInstance();
+    private var conn:Connection = Connection.getConnection();
        private var doSkip:Boolean = false;
     
     [Bindable]
index 3e9cdaa8338d78668b3c5d670cf52e052ad225f7..e5cd2339a116ff17017ac92990a9496bbcb3090f 100644 (file)
@@ -20,7 +20,7 @@ package net.systemeD.potlatch2.save {
         }
 
         private function save(callback:Function):void {
-            var conn:Connection = Connection.getConnectionInstance();
+            var conn:Connection = Connection.getConnection();
             if (conn.hasAccessToken()) {
                 callback();
             } else {
@@ -51,7 +51,7 @@ package net.systemeD.potlatch2.save {
                 PopUpManager.createPopUp(Application(Application.application), SaveDialog, true));
             PopUpManager.centerPopUp(saveDialog);
 
-                       if (Connection.getConnectionInstance().getActiveChangeset()) {
+                       if (Connection.getConnection().getActiveChangeset()) {
                                saveDialog.dontPrompt();
                        }
         }
index 89e4d9f059bb1155dff69dcc5fbc95a5f27651cb..6be59e0158691dea2a68bb2cdeb6f77f4f200c6e 100644 (file)
@@ -63,7 +63,7 @@ package net.systemeD.potlatch2.utils {
               var marker:Marker = layer.createMarker(tags, lat, lon);
             }
                        default xml namespace = new Namespace("");
-            layer.paint.updateEntityUIs(layer.getObjectsByBbox(map.edge_l,map.edge_r,map.edge_t,map.edge_b), true, false);
+            layer.paint.updateEntityUIs(true, false);
         }
 
         private function get layer():VectorLayer {
index e4b61955e42bcba91bf62ca41156ae0fcaabcf5e..7e2284236740c2db5cc6c205c1c01df9bc89c1af 100644 (file)
@@ -50,7 +50,7 @@ package net.systemeD.potlatch2.utils {
                        filesloaded++;
                        if (filesloaded==filenames.length) { 
                                doImport();
-                               paint.updateEntityUIs(container.getObjectsByBbox(paint.map.edge_l, paint.map.edge_r, paint.map.edge_t, paint.map.edge_b), false, false);
+                               paint.updateEntityUIs(false, false);
                                if (callback!=null) { callback(true); }
                        }
                }
index d4bc6ece5dd23c6850de70b77f0fe272fdf9deef..812c50781fd2675049904937c16d71f32ff723b8 100644 (file)
@@ -71,7 +71,7 @@ package net.systemeD.potlatch2.utils {
                        }
             
                        default xml namespace = new Namespace("");
-                       layer.paint.updateEntityUIs(layer.getObjectsByBbox(left,right,top,bottom), false, false);
+                       layer.paint.updateEntityUIs(false, false);
                }
 
                private function get layer():VectorLayer {