The branch now loads maps again. Lots of messy code; most of the VectorLayer stuff...
authorRichard Fairhurst <richard@systemeD.net>
Sat, 21 May 2011 21:43:15 +0000 (22:43 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sat, 21 May 2011 21:43:15 +0000 (22:43 +0100)
17 files changed:
REFACTOR.txt
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/MapPaint.as
net/systemeD/halcyon/VectorLayer.as
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/Trace.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/potlatch2/BackgroundSelector.mxml
net/systemeD/potlatch2/EditController.as
net/systemeD/potlatch2/TagViewer.mxml
net/systemeD/potlatch2/collections/VectorBackgrounds.as
net/systemeD/potlatch2/mygpx/MyGpxDialog.mxml
net/systemeD/potlatch2/save/OAuthPanel.mxml
net/systemeD/potlatch2/utils/BikeShopLoader.as
net/systemeD/potlatch2/utils/BugLoader.as
net/systemeD/potlatch2/utils/TrackLoader.as
potlatch2.mxml

index 632e6ae..7945e60 100644 (file)
@@ -4,30 +4,34 @@ Aims:
 - to enable multiple Maps to be shown on-screen (e.g. for junction editor)
 - to bring Connection and VectorLayer code together
 
-Map.as changes:
-becomes a collection of MapPaint objects, all with the same lat/long/scale
+Current status:
+- it loads a map and lets you edit it!
+- VectorLayers (of any shape) will not work - lots of them are commented out
+- Save/OAuth not tested
+
+== Changes overall ==
+
+Map.as becomes a collection of MapPaint objects, all with the same lat/long/scale
 (plus a backdrop sprite and a background imagery sprite)
-√ move listeners to Connection to MapPaint (e.g. new way created in the Connection - MapPaint should know about it, not Map)
+Map.editableLayer returns a reference to the single MapPaint object where isBackground is false
+
+MapPaint.as gains a reference to a Connection - i.e. the source data for this layer
 
-MapPaint.as changes:
-- gains a reference to a Connection - i.e. the source data for this layer
-- needs an 'interactive' flag
-√ UpdateEntityUIs no longer needs a set of entities passing to it - it can read directly from the Connection
-- consider whether it's better to have a backreference to Map or for Map to update edges/lat/long/scale etc.
+== Stuff to look at ==
+
+There are lots more of these throughout the code, marked with fixmes of the form '>>>> REFACTOR'
+
+MapPaint.as
 - wayuis, nodeuis etc. should ideally be private
 - removeLayer should blank
 
-VectorLayer.as changes:
+VectorLayer.as is completely derelict
 - move into Connection
+- references in Loader classes etc. currently commented out
+- everything derived from VectorLayers (e.g. Traces, Bugs, BikeShopLoader) needs completely refactoring
 
 Global changes:
-- move lots of connection.map to connection.map.editableLayer
-- remove all references to getConnection etc. - there can now be more than one Connection
 - remove all back-references to Map except where necessary for lat/long/scale
-- getParam is broken - there needs to be a global equivalent (not in Connection) for stuff sent via flashvars - i.e. loaderInfo.parameters (but that's Flex-only)
-- Look for Connection. - lots of static stuff which shouldn't be that any more
-
-Further refactoring probably needed:
-- move AttentionEvent stuff (some may be commented out)
-- Traces (e.g. in potlatch2.mxml) - seems a bit mixed up
-- refactor tileset/setbackground stuff?
+- getParam is messy - stuff sent via flashvars needs somewhere to live: currently in Globals which is ugly
+- AttentionEvents are derelict and commented out
+- tileset/setbackground stuff is screwed up again and needs refactoring a little
index c0fdd69..a2299f8 100644 (file)
@@ -75,7 +75,7 @@ package net.systemeD.halcyon {
                /** background tile object */
                public var tileset:TileSet; 
                /** background tile URL, name and scheme */
-               private var tileparams:Object={ url:'' }; 
+               public var tileparams:Object={ url:'' }; 
                /** show all objects, even if unstyled? */
                public var showall:Boolean=true; 
                
@@ -224,6 +224,7 @@ package net.systemeD.halcyon {
         * The bounding box for the download is taken from the current map edges.
         */
                public function download():void {
+trace("download "+edge_l+","+edge_r+","+edge_t+","+edge_b)
                        this.dispatchEvent(new MapEvent(MapEvent.DOWNLOAD, {minlon:edge_l, maxlon:edge_r, maxlat:edge_t, minlat:edge_b} ));
                        for (var i:uint=0; i<paintContainer.numChildren; i++)
                                getLayerAt(i).connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
index 5afeae1..f87cfee 100644 (file)
@@ -60,8 +60,7 @@ package net.systemeD.halcyon {
                        var s:Sprite, l:int;
 
                        // Set up stylesheet
-                       ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
-                       ruleset.loadFromCSS(styleurl);
+                       setStyle(styleurl);
 
                        // Listen for changes on this Connection
             connection.addEventListener(Connection.NEW_WAY, newWayCreatedListener);
@@ -341,16 +340,16 @@ package net.systemeD.halcyon {
                
                /** Switch to new MapCSS. */
                public function setStyle(url:String):void {
-                       ruleset=new RuleSet(MINSCALE,MAXSCALE,redraw,redrawPOIs);
+                       ruleset=new RuleSet(map.MINSCALE,map.MAXSCALE,redraw,redrawPOIs);
                        ruleset.loadFromCSS(url);
         }
 
                // >>>> REFACTOR: remove this
                public function findSource():VectorLayer {
-                       var v:VectorLayer;
-                       for each (v in map.vectorlayers) {
-                               if (v.paint==this) { return v; }
-                       }
+//                     var v:VectorLayer;
+//                     for each (v in map.vectorlayers) {
+//                             if (v.paint==this) { return v; }
+//                     }
                        return null;
                }
 
index 4631b0e..04e2ba8 100644 (file)
@@ -37,7 +37,8 @@ package net.systemeD.halcyon {
                        name=n;
                        map=m;
                        style=s;
-                       paint=new MapPaint(m,0,0);
+                               // >>>> REFACTOR: VectorLayer commented out
+//                     paint=new MapPaint(m,0,0);
                        redrawFromCSS(style);
                }
 
@@ -52,9 +53,11 @@ package net.systemeD.halcyon {
         * e.g. <code>layer.paint.updateEntityUIs(...);</code>
         */
                public function createNode(tags:Object,lat:Number,lon:Number):Node {
-                       var node:Node = new Node(this, negativeID, 0, tags, true, lat, lon);
-                       nodes[negativeID]=node; negativeID--;
-                       return node;
+                               // >>>> REFACTOR: VectorLayer commented out
+//                     var node:Node = new Node(this, negativeID, 0, tags, true, lat, lon);
+//                     nodes[negativeID]=node; negativeID--;
+//                     return node;
+                       return null;
                }
 
         /**
@@ -62,9 +65,11 @@ package net.systemeD.halcyon {
         * @param nodes An array of Node objects
         */
                public function createWay(tags:Object,nodes:Array):Way {
-                       var way:Way = new Way(this, negativeID, 0, tags, true, nodes.concat());
-                       ways[negativeID]=way; negativeID--;
-                       return way;
+                               // >>>> REFACTOR: VectorLayer commented out
+//                     var way:Way = new Way(this, negativeID, 0, tags, true, nodes.concat());
+//                     ways[negativeID]=way; negativeID--;
+//                     return way;
+                       return null;
                }
 
         /**
@@ -72,9 +77,11 @@ package net.systemeD.halcyon {
         * @param members An array of RelationMember objects
         */
                public function createRelation(tags:Object,members:Array):Relation {
-            var relation:Relation = new Relation(this, negativeID, 0, tags, true, members.concat());
-                       relations[negativeID]=relation; negativeID--;
-            return relation;
+                               // >>>> REFACTOR: VectorLayer commented out
+//                     var relation:Relation = new Relation(this, negativeID, 0, tags, true, members.concat());
+//                     relations[negativeID]=relation; negativeID--;
+//                     return relation;
+                       return null;
                }
 
         /**
@@ -91,12 +98,14 @@ package net.systemeD.halcyon {
               id = negativeID;
               negativeID--;
             }
-            var marker:Marker = markers[id];
-            if (marker == null) {
-              marker = new Marker(this, id, 0, tags, true, lat, lon);
-              markers[id]=marker;
-            }
-            return marker;
+                               // >>>> REFACTOR: VectorLayer commented out
+//            var marker:Marker = markers[id];
+//            if (marker == null) {
+//              marker = new Marker(this, id, 0, tags, true, lat, lon);
+//              markers[id]=marker;
+//            }
+//            return marker;
+                       return null;
         }
 
         public function registerPOI(node:Node):void {
@@ -161,7 +170,7 @@ package net.systemeD.halcyon {
                                }
                                paint.wayuis[oldWay.id].redraw();
                                delete ways[oldWay.id];
-                               map.paint.createWayUI(newWay);
+                               paint.createWayUI(newWay);
                                return newWay;
 
                        } else if (entity is Node && !entity.hasParentWays) {
@@ -169,12 +178,14 @@ package net.systemeD.halcyon {
                                // ** should be properly undoable
                                oldNode=Node(entity);
                                unregisterPOI(oldNode);
-                               var newPoiAction:CreatePOIAction = new CreatePOIAction(
-                                       this, oldNode.getTagsCopy(), oldNode.lat, oldNode.lon);
-                               MainUndoStack.getGlobalStack().addAction(newPoiAction);
-                               paint.deleteNodeUI(oldNode);
-                               delete nodes[oldNode.id];
-                               return newPoiAction.getNode();
+                               // >>>> REFACTOR: VectorLayer commented out
+//                             var newPoiAction:CreatePOIAction = new CreatePOIAction(
+//                                     this, oldNode.getTagsCopy(), oldNode.lat, oldNode.lon);
+//                             MainUndoStack.getGlobalStack().addAction(newPoiAction);
+//                             paint.deleteNodeUI(oldNode);
+//                             delete nodes[oldNode.id];
+//                             return newPoiAction.getNode();
+                               return null;
                        }
                        return null;
                }
index dced4d3..5f5737c 100644 (file)
@@ -7,6 +7,7 @@ package net.systemeD.halcyon.connection {
     import net.systemeD.halcyon.AttentionEvent;
     import net.systemeD.halcyon.MapEvent;
     import net.systemeD.halcyon.connection.actions.*;
+    import net.systemeD.halcyon.Globals;
 
        public class Connection extends EventDispatcher {
 
@@ -24,7 +25,9 @@ package net.systemeD.halcyon.connection {
                }
 
         public function getParam(name:String, defaultValue:String):String {
-            return params[name] == null ? defaultValue : params[name];
+                       if (params[name]) return params[name];
+                       if (Globals.vars.flashvars[name]) return Globals.vars.flashvars[name];
+                       return defaultValue;
         }
 
         public function get apiBase():String {
index 4c7597e..2c0c1a5 100644 (file)
@@ -74,8 +74,9 @@ package net.systemeD.halcyon.connection {
 
         private function get layer():VectorLayer {
             if (!_layer) {
-                _layer=new VectorLayer(filename,map,STYLESHEET);
-                map.addVectorLayer(_layer);
+                               // >>>> REFACTOR: VectorLayer commented out
+                // _layer=new VectorLayer(filename,map,STYLESHEET);
+                // map.addVectorLayer(_layer);
             }
             return _layer;
         }
index 4f72b73..8a428fc 100644 (file)
@@ -38,15 +38,16 @@ package net.systemeD.halcyon.connection {
 
             var mapVars:URLVariables = new URLVariables();
             mapVars.bbox= left+","+bottom+","+right+","+top;
+trace("requesting "+mapVars.bbox);
 
-            var mapRequest:URLRequest = new URLRequest(Connection.apiBaseURL+"map");
+            var mapRequest:URLRequest = new URLRequest(apiBaseURL+"map");
             mapRequest.data = mapVars;
 
             sendLoadRequest(mapRequest);
                }
 
                override public function loadEntityByID(type:String, id:Number):void {
-                       var url:String=Connection.apiBaseURL + type + "/" + id;
+                       var url:String=apiBaseURL + type + "/" + id;
                        if (type=='way') url+="/full";
                        sendLoadRequest(new URLRequest(url));
                }
@@ -130,7 +131,7 @@ package net.systemeD.halcyon.connection {
               changesetXML.changeset.appendChild(tagXML);
             }        
 
-                       sendOAuthPut(Connection.apiBaseURL+"changeset/create",
+                       sendOAuthPut(apiBaseURL+"changeset/create",
                                                 changesetXML,
                                                 changesetCreateComplete, changesetCreateError, recordStatus);
            }
@@ -151,7 +152,7 @@ package net.systemeD.halcyon.connection {
             var cs:Changeset = getActiveChangeset();
                        if (!cs) return;
                        
-                       sendOAuthPut(Connection.apiBaseURL+"changeset/"+cs.id+"/close",
+                       sendOAuthPut(apiBaseURL+"changeset/"+cs.id+"/close",
                                                 null,
                                                 changesetCloseComplete, changesetCloseError, recordStatus);
                        closeActiveChangeset();
@@ -215,7 +216,7 @@ package net.systemeD.halcyon.connection {
 
             // now actually upload them
             // make an OAuth query
-            var url:String = Connection.apiBaseURL+"changeset/" + changeset.id + "/upload";
+            var url:String = apiBaseURL+"changeset/" + changeset.id + "/upload";
 
             // build the actual request
                        var serv:HTTPService=new HTTPService();
@@ -429,8 +430,7 @@ package net.systemeD.halcyon.connection {
             if (traces_loaded && !refresh) {
               dispatchEvent(new Event(TRACES_LOADED));
             } else {
-              sendOAuthGet(Connection.apiBaseURL+"user/gpx_files",
-                          tracesLoadComplete, errorOnMapLoad, mapLoadStatus); //needs error handlers
+              sendOAuthGet(apiBaseURL+"user/gpx_files", tracesLoadComplete, errorOnMapLoad, mapLoadStatus); //needs error handlers
               dispatchEvent(new Event(LOAD_STARTED)); //specific to map or reusable?
             }
         }
@@ -448,7 +448,7 @@ package net.systemeD.halcyon.connection {
         }
 
         override public function fetchTrace(id:Number, callback:Function):void {
-            sendOAuthGet(Connection.apiBaseURL+"gpx/"+id+"/data.xml", 
+            sendOAuthGet(apiBaseURL+"gpx/"+id+"/data.xml", 
                                function(e:Event):void { 
                        dispatchEvent(new Event(LOAD_COMPLETED));
                                        callback(e);
index 551e87f..bc0922a 100644 (file)
 
        <mx:HBox>
        <mx:Button label="Edit..." click="Application.application.bgButton.close(); new BackgroundDialog().init('Background imagery',background,Imagery.instance());" />
-       <mx:Button label="Vector file..." click="Application.application.bgButton.close(); new VectorSourceDialog().init();" />
+       <mx:Button label="Vector file..." click="Application.application.bgButton.close(); " />
        </mx:HBox>
 
        <mx:Script><![CDATA[
+               // >>>> REFACTOR: vector file button was click="Application.application.bgButton.close(); new VectorSourceDialog().init();" but that's amazingly broken -->
+
                import net.systemeD.halcyon.*;
                import net.systemeD.halcyon.connection.*;
                import net.systemeD.potlatch2.*;
index 48a4771..7cdbae2 100644 (file)
@@ -4,6 +4,7 @@ package net.systemeD.potlatch2 {
     import net.systemeD.halcyon.MapEvent;
     import net.systemeD.halcyon.connection.*;
     import net.systemeD.halcyon.VectorLayer;
+    import net.systemeD.halcyon.Globals;
     import net.systemeD.potlatch2.controller.*;
     import net.systemeD.potlatch2.FunctionKeyManager;
        import mx.managers.CursorManager;
@@ -45,9 +46,9 @@ package net.systemeD.potlatch2 {
             this.tagViewer = tagViewer;
                        this.toolbox = toolbox;
                        this.toolbox.init(this);
-            this.maximiseFunction = Connection.getParam("maximise_function", null);
-            this.minimiseFunction = Connection.getParam("minimise_function", null);
-            this.moveFunction = Connection.getParam("move_function", null);
+            this.maximiseFunction = Globals.vars.flashvars["maximise_function"];
+            this.minimiseFunction = Globals.vars.flashvars["minimise_function"];
+            this.moveFunction     = Globals.vars.flashvars["move_function"];
 
             map.parent.addEventListener(MouseEvent.MOUSE_MOVE, mapMouseEvent);
             map.parent.addEventListener(MouseEvent.MOUSE_UP, mapMouseEvent);
index 582d921..eb9b636 100644 (file)
 
       public var mapFeatures:MapFeatures;
       private var selectedEntity:Entity;
+      private var connection:Connection;
       private var currentCategorySelector:CategorySelector;
       private var categorySelectors:Object = {};       // hash of categorySelectors for each limitType
       private var feature:Feature = null;
 
          public function setEntity(entities:Array, layer:VectorLayer=null):void {
                UIComponent.suspendBackgroundProcessing();
+               connection=null;
 
                var firstSelected:Entity=null;
                if (entities.length==1) { firstSelected=entities[0]; }
                } else if (entities.length==1) {
                        // Single entity selected, so show tag panel
                        selectedEntity=firstSelected;
+                       connection=firstSelected.connection;
                        if (selectedEntity!=null) { selectedEntity.addEventListener(Connection.TAG_CHANGED, tagChanged); }
                        if (advancedID!=null) { setupAdvanced(firstSelected); }
                        if (firstSelected is Relation) { stack.addChild(membersVBox); }
                        selectedEntity.addEventListener(Connection.TAG_CHANGED, tagChanged);
             sidebar.selectedChild = multiplePanel;
                        setupMultiAdvanced(selectedEntity);
-
+                       connection=entities[0].connection;
+                       
                } else {
                        //The selection contains elements which can't be edited all together.
                        sidebar.selectedChild = multipleInvalidPanel;
           // but is at least robust for any kind of change.
           // Figuring out a better way is someone else's FIXME
 
-          var conn:Connection = Connection.getConnection();
-          var rel:Relation = selectedEntity as Relation
+          var rel:Relation = selectedEntity as Relation;
           var action:CompositeUndoableAction = new CompositeUndoableAction("Rearrange relation members for "+rel);
 
           // drop members
           for each(var memberObject:Object in membersGrid.dataProvider) {
             var e:Entity;
             var id:Number = memberObject.id;
-            if(memberObject.type == 'node') {
-              e = conn.getNode(id);
-            } else if (memberObject.type == 'way') {
-              e = conn.getWay(id);
-            } else if (memberObject.type == 'relation') {
-              e = conn.getRelation(id);
+                       switch (memberObject.type) {
+                               case 'node':            e = connection.getNode(id); break;
+               case 'way':                     e = connection.getWay(id); break;
+                               case 'relation':        e = connection.getRelation(id); break;
             }
             rel.appendMember(new RelationMember(e, memberObject.role), action.push);
           }
       private function editRelation(id:Number):void {
           var panel:RelationEditorPanel = RelationEditorPanel(
               PopUpManager.createPopUp(Application(Application.application), RelationEditorPanel, true));
-          panel.setRelation(Connection.getConnection().getRelation(id));
+          panel.setRelation(connection.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.getConnection().apiBase + '../../browse/'
+              var urlBase:String = connection.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.getConnection().getRelation(id);
+               var rel:Relation=connection.getRelation(id);
                if (index>-1) {
                        rel.removeMemberByIndex(index, MainUndoStack.getGlobalStack().addAction);
                } else if (selectedEntity is EntityCollection) {
index 6646e3d..b84f895 100644 (file)
@@ -47,9 +47,10 @@ package net.systemeD.potlatch2.collections {
                   if (set.url) {
                     if (set.@loaded == "true") {
                       name ||= 'GPX file';
-                      var layer:VectorLayer = new VectorLayer(name, _map, 'stylesheets/gpx.css');
-                      _map.addVectorLayer(layer);
-                      var gpxImporter:GpxImporter = new GpxImporter(layer, layer.paint, [String(set.url)]);
+                                         // >>>> 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");
                     }
index 3ca3c5c..bdce15c 100644 (file)
         PopUpManager.centerPopUp(this);
         this.addEventListener(CloseEvent.CLOSE, myGpxDialog_close);
 
-        conn = Connection.getConnection();
+               // >>>> REFACTOR: really horrible way of getting both map and connection
         map = Globals.vars.root;
+               conn = map.editableLayer.connection;
 
         conn.addEventListener(Connection.TRACES_LOADED, onTracesLoaded);
-        SaveManager.ensureAccess(fetchList);
+        SaveManager.ensureAccess(fetchList, conn);
     }
 
     private function myGpxDialog_close(evt:CloseEvent):void {
index c01a542..5a9285f 100644 (file)
         private function getRequestToken():void {
             var sig:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
             var consumer:OAuthConsumer = getConsumer();
-            var url:String = Connection.getParam("oauth_request_url", "http://127.0.0.1:3000/oauth/request_token");
+            var url:String = connection.getParam("oauth_request_url", "http://127.0.0.1:3000/oauth/request_token");
             
             var params:Object = new Object();
             var oauthRequest:OAuthRequest = new OAuthRequest("GET", url, params, consumer, null);
             trace("Yay! response: "+URLLoader(event.target).data);
             requestToken = getResponseToken(URLLoader(event.target));
             
-            var url:String = Connection.getParam("oauth_auth_url", "http://127.0.0.1:3000/oauth/authorize");            
+            var url:String = connection.getParam("oauth_auth_url", "http://127.0.0.1:3000/oauth/authorize");            
             link.label = url;
                        authoriseURL = url + "?oauth_token="+requestToken.key;
                        progress.visible = false;
         private function getAccessToken():void {
             var sig:IOAuthSignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
             var consumer:OAuthConsumer = getConsumer();
-            var url:String = Connection.getParam("oauth_access_url", "http://127.0.0.1:3000/oauth/access_token");
+            var url:String = connection.getParam("oauth_access_url", "http://127.0.0.1:3000/oauth/access_token");
 
             var oauthRequest:OAuthRequest = new OAuthRequest("GET", url, null, consumer, requestToken);
             var urlStr:Object = oauthRequest.buildRequest(sig, OAuthRequest.RESULT_TYPE_URL_STRING)
         }
         
         private function getConsumer():OAuthConsumer {
-            var key:String = Connection.getParam("oauth_consumer_key", "");
-            var secret:String = Connection.getParam("oauth_consumer_secret", "");
+            var key:String = connection.getParam("oauth_consumer_key", "");
+            var secret:String = connection.getParam("oauth_consumer_secret", "");
             return new OAuthConsumer(key, secret);
         }
                
index 6be59e0..86f203c 100644 (file)
@@ -67,14 +67,15 @@ package net.systemeD.potlatch2.utils {
         }
 
         private function get layer():VectorLayer {
-            if (!_layer) {
-                var policyFile:String = bikeShopBaseURL+"crossdomain.xml";
-                Security.loadPolicyFile(policyFile);
-
-                _layer=new VectorLayer(name,map,STYLESHEET);
-                map.addVectorLayer(_layer);
-            }
-            return _layer;
+                       // >>>> REFACTOR: VectorLayer commented out
+            // if (!_layer) {
+            //     var policyFile:String = bikeShopBaseURL+"crossdomain.xml";
+            //     Security.loadPolicyFile(policyFile);
+            //     _layer=new VectorLayer(name,map,STYLESHEET);
+            //     map.addVectorLayer(_layer);
+            // }
+            // return _layer;
+                       return null;
         }
     }
 }
\ No newline at end of file
index 3ba731f..5b70251 100644 (file)
@@ -33,15 +33,15 @@ package net.systemeD.potlatch2.utils {
 
 
         private function get layer():VectorLayer {
-            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;
+                       // >>>> 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;
         }
     }
 }
\ No newline at end of file
index 812c507..2835030 100644 (file)
@@ -75,12 +75,14 @@ package net.systemeD.potlatch2.utils {
                }
 
                private function get layer():VectorLayer {
-                       var vl:VectorLayer=map.findVectorLayer('GPS tracks');
-                       if (!vl) {
-                               vl=new VectorLayer('GPS tracks',map,STYLESHEET);
-                               map.addVectorLayer(vl);
-                       }
-                       return vl;
+                       // >>>> REFACTOR: VectorLayer commented out
+                       // var vl:VectorLayer=map.findVectorLayer('GPS tracks');
+                       // if (!vl) {
+                       //      vl=new VectorLayer('GPS tracks',map,STYLESHEET);
+                       //      map.addVectorLayer(vl);
+                       // }
+                       // return vl;
+                       return null;
                }
                
                private function greatCircle(lat1:Number,lon1:Number,lat2:Number,lon2:Number):Number {
index 133c5f4..d7744c2 100644 (file)
@@ -37,7 +37,7 @@
                          else if (event.index==1) { new MyGpxDialog().init(); } 
                                              else { mx.controls.Menu(gpsButton.popUp).selectedIndex=0; 
                                                     mx.controls.Menu(gpsButton.popUp).selectedIndex=0; /* Yes, we do need to call it twice */
-                                                    theMap.removeVectorLayer(theMap.findVectorLayer('GPS tracks')); }">
+                                                    theMap.removeLayerByName('GPS tracks'); }">
                        <mx:dataProvider>
                                <mx:Array>
                                        <mx:Object label="GPS data" id="gpsData" />
                        Globals.vars.root = map_area.rawChildren;                       // set up global reference to root level
                        var _root:IChildList = map_area.rawChildren;            // convenient local shorthand
                        Globals.vars.nocache = loaderInfo.parameters['nocache'] == 'true';
+                       Globals.vars.flashvars = loaderInfo.parameters;
 
                        // populate sharedObject with loaderInfo parameters if supplied
                        var obj:SharedObject = SharedObject.getLocal("user_state");
                        for (k in SharedObject.getLocal('user_state').data) params[k]=SharedObject.getLocal('user_state').data[k];
 
                        // Create map
-                       theMap=new Map(params);
+                       theMap=new Map();
+                       theMap.backdrop=b;
+            theMap.updateSize(w,h);
+                       theMap.addEventListener(MapEvent.SCALE, scaleHandler);
+
+                       yahoo=new Yahoo(theMap);
+                       yahoo.hide();
+                       _root.addChild(yahoo);
+                       _root.addChild(theMap);
 
                        // Initialise 900913 background
                        // >>>> REFACTOR: something odd about accessing map.tileparams here...
-                       map.tileset.blocks=[new RegExp("google","i")];  // hard-coded block on Google tiles
-                       map.tileset.init(map.tileparams, false, 
-                                        initparams['background_dim']    ==null ? true  : initparams['background_dim'],
-                                        initparams['background_sharpen']==null ? false : initparams['background_sharpen']);
+                       theMap.tileset.blocks=[new RegExp("google","i")];       // hard-coded block on Google tiles
+                       theMap.tileset.init(theMap.tileparams, false, 
+                                           params['background_dim']    ==null ? true  : params['background_dim'],
+                                           params['background_sharpen']==null ? false : params['background_sharpen']);
 
                        // Add core data layer
                        // >>>> REFACTOR: shouldn't be hardcoded to XMLConnection
-                       var conn:Connection = new XMLConnection("Main", initparams['api'], initparams['policy'], initparams);
+                       var conn:Connection = new XMLConnection("Main", params['api'], params['policy'], params);
             conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
             conn.addEventListener(Connection.SAVE_STARTED, onDataStart);
                        conn.addEventListener(MapEvent.ERROR, onMapError);
                        conn.addEventListener(AttentionEvent.ATTENTION, onAttention);
                        conn.addEventListener(AttentionEvent.ALERT, onAlert);
-                       map.addLayer(conn,initparams['styleurl'],false);
+                       // >>>> REFACTOR: shouldn't be trying to find out stylesheet from here
+                       theMap.addLayer(conn,params['styleurl'] ? params['styleurl'] : 'stylesheets/potlatch.css',false);
 
                        // Set start position of map
                        // >>>> REFACTOR: what happens if lat/lon/zoom not supplied? (Hurleston GPX case)
-                       map.init(initparams['lat'], initparams['lon'], initparams['zoom']);
+                       theMap.init(params['lat'], params['lon'], params['zoom']);
 
             // Auto-load vector backgrounds from config
             // This could go spectacularly wrong if map.init completes before the event listener below is added
             theMap.addEventListener(MapEvent.INITIALISED, function(e:Event):void { VectorBackgrounds.instance().init(theMap); });
 
-                       theMap.backdrop=b;
-                       yahoo=new Yahoo(theMap);
-                       yahoo.hide();
-                       _root.addChild(yahoo);
-                       _root.addChild(theMap);
-            theMap.updateSize(w,h);
-                       theMap.addEventListener(MapEvent.SCALE, scaleHandler);
-
                        // add attribution/logo sprite
                        var overlay:Sprite=new Sprite();
                        var attribution:TextField=new TextField();
                 if (conn.hasAccessToken()) { 
                     loadTrace(id);
                 } else {
-                    SaveManager.ensureAccess(function ():void { loadTrace(id); });
+                    SaveManager.ensureAccess(function ():void { loadTrace(id); }, conn);
                 }
             }
 
                                var gpx:GpxImporter=new GpxImporter(vectorlayer, vectorlayer.paint, [vectorlayer.url], 
                                                                    function(success:Boolean,message:String=null):void {
                                        if (!success) return;
-                                       theMap.addVectorLayer(vectorlayer);
+                                       // >>>> REFACTOR: vectorlayer commented out
+//                                     theMap.addVectorLayer(vectorlayer);
                                        dispatchEvent(new Event("layers_changed"));
                                                                    }, false);
                        }
             // force_auth == force => checks for access token, and displays OAuth panel if needed
             var force_auth:String = loaderInfo.parameters["force_auth"];
             if (!conn.hasAccessToken() && force_auth == 'force') {
-              SaveManager.ensureAccess(onAccessChecked);
+              SaveManager.ensureAccess(onAccessChecked, conn);
             }
 
             // show help dialog on startup, if required