fix issue with ways in relations not displaying if you panned about; make the stylesh...
[potlatch2.git] / net / systemeD / halcyon / connection / Connection.as
index d4d13c19e7355cad06d79349ab4829bb268be19e..965d12f8da73196e6950a58a390e386bccbf604b 100755 (executable)
@@ -7,20 +7,21 @@ package net.systemeD.halcyon.connection {
 
        public class Connection extends EventDispatcher {
 
-        private static var CONNECTION_TYPE:String = "AMF";
         private static var connectionInstance:Connection = null;
 
-        protected static var policyURL:String = "http://127.0.0.1:3000/api/crossdomain.xml";
-        protected static var apiBaseURL:String = "http://127.0.0.1:3000/api/0.6/";
+        protected static var policyURL:String;
+        protected static var apiBaseURL:String;
+        protected static var params:Object;
 
-        public static function getConnection(api:String,policy:String,conn:String):Connection {
-                       
-                       policyURL=policy;
-                       apiBaseURL=api;
-                       CONNECTION_TYPE=conn;
-                       
+        public static function getConnection(initparams:Object=null):Connection {
             if ( connectionInstance == null ) {
-                if ( CONNECTION_TYPE == "XML" )
+            
+                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
                     connectionInstance = new AMFConnection();
@@ -28,6 +29,19 @@ package net.systemeD.halcyon.connection {
             return connectionInstance;
         }
 
+        public static function getParam(name:String, defaultValue:String):String {
+            trace("Returning param "+name+" as "+(params[name] == null ? defaultValue : params[name]));
+            return params[name] == null ? defaultValue : params[name];
+        }
+
+        public static function get apiBase():String {
+            return apiBaseURL;
+        }
+
+        public static function get serverName():String {
+            return getParam("serverName", "Localhost");
+        }
+                
                public static function getConnectionInstance():Connection {
             return connectionInstance;
                }
@@ -35,11 +49,18 @@ package net.systemeD.halcyon.connection {
                public function getEnvironment(responder:Responder):void {}
 
         // connection events
+        public static var LOAD_STARTED:String = "load_started";
+        public static var LOAD_COMPLETED:String = "load_completed";
+        public static var SAVE_STARTED:String = "save_started";
+        public static var SAVE_COMPLETED:String = "save_completed";
+        public static var NEW_CHANGESET:String = "new_changeset";
+        public static var NEW_CHANGESET_ERROR:String = "new_changeset_error";
         public static var NEW_NODE:String = "new_node";
         public static var NEW_WAY:String = "new_way";
         public static var NEW_RELATION:String = "new_relation";
         public static var NEW_POI:String = "new_poi";
         public static var TAG_CHANGE:String = "tag_change";
+        public static var NODE_MOVED:String = "node_moved";
 
         // store the data we download
         private var negativeID:Number = -1;
@@ -47,6 +68,7 @@ package net.systemeD.halcyon.connection {
         private var ways:Object = {};
         private var relations:Object = {};
         private var pois:Array = [];
+        private var changeset:Changeset = null;
 
         protected function get nextNegative():Number {
             return negativeID--;
@@ -54,23 +76,27 @@ package net.systemeD.halcyon.connection {
 
         protected function setNode(node:Node):void {
             nodes[node.id] = node;
-            dispatchEvent(new EntityEvent(NEW_NODE, node));
+            if (node.loaded) { sendEvent(new EntityEvent(NEW_NODE, node)); }
         }
 
         protected function setWay(way:Way):void {
             ways[way.id] = way;
-            dispatchEvent(new EntityEvent(NEW_WAY, way));
+            if (way.loaded) { sendEvent(new EntityEvent(NEW_WAY, way)); }
         }
 
         protected function setRelation(relation:Relation):void {
             relations[relation.id] = relation;
-            dispatchEvent(new EntityEvent(NEW_RELATION, relation));
+            if (relation.loaded) { sendEvent(new EntityEvent(NEW_RELATION, relation)); }
         }
 
+               public function sendEvent(e:*):void {
+                       dispatchEvent(e);
+               }
+
         protected function registerPOI(node:Node):void {
             if ( pois.indexOf(node) < 0 ) {
                 pois.push(node);
-                dispatchEvent(new EntityEvent(NEW_POI, node));
+                sendEvent(new EntityEvent(NEW_POI, node));
             }
         }
 
@@ -81,6 +107,11 @@ package net.systemeD.halcyon.connection {
             }
         }
 
+        protected function setActiveChangeset(changeset:Changeset):void {
+            this.changeset = changeset;
+            sendEvent(new EntityEvent(NEW_CHANGESET, changeset));
+        }
+        
         public function getNode(id:Number):Node {
             return nodes[id];
         }
@@ -94,19 +125,19 @@ package net.systemeD.halcyon.connection {
         }
 
         public function createNode(tags:Object, lat:Number, lon:Number):Node {
-            var node:Node = new Node(nextNegative, 0, tags, lat, lon);
+            var node:Node = new Node(nextNegative, 0, tags, true, lat, lon);
             setNode(node);
             return node;
         }
 
         public function createWay(tags:Object, nodes:Array):Way {
-            var way:Way = new Way(nextNegative, 0, tags, nodes.concat());
+            var way:Way = new Way(nextNegative, 0, tags, true, nodes.concat());
             setWay(way);
             return way;
         }
 
         public function createRelation(tags:Object, members:Array):Relation {
-            var relation:Relation = new Relation(nextNegative, 0, tags, members.concat());
+            var relation:Relation = new Relation(nextNegative, 0, tags, true, members.concat());
             setRelation(relation);
             return relation;
         }
@@ -132,11 +163,20 @@ package net.systemeD.halcyon.connection {
             return list;
         }
 
+        public function getActiveChangeset():Changeset {
+            return changeset;
+        }
+        
         // these are functions that the Connection implementation is expected to
         // provide. This class has some generic helpers for the implementation.
                public function loadBbox(left:Number, right:Number,
                                                                top:Number, bottom:Number):void {
            }
+           
+           public function setAppID(id:Object):void {}
+           public function setAuthToken(id:Object):void {}
+           public function createChangeset(tags:Object):void {}
+           public function uploadChanges():void {}
     }
 
 }