Give Entity a back-reference to the Connection it belongs to. (If we figure out anoth...
authorRichard Fairhurst <richard@systemeD.net>
Sat, 21 May 2011 13:57:29 +0000 (14:57 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sat, 21 May 2011 13:57:29 +0000 (14:57 +0100)
13 files changed:
net/systemeD/halcyon/Elastic.as
net/systemeD/halcyon/VectorLayer.as
net/systemeD/halcyon/connection/AMFConnection.as
net/systemeD/halcyon/connection/Changeset.as
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/connection/EntityCollection.as
net/systemeD/halcyon/connection/Marker.as
net/systemeD/halcyon/connection/Node.as
net/systemeD/halcyon/connection/Relation.as
net/systemeD/halcyon/connection/Way.as
net/systemeD/halcyon/connection/XMLBaseConnection.as
net/systemeD/halcyon/connection/XMLConnection.as

index fdb521e36749dbcb0951afa482fe4f0b5d10f01c..7daf83cd5c5be9c91829f9a1bd2f2d04a2f3f690 100644 (file)
@@ -25,7 +25,7 @@ package net.systemeD.halcyon {
                public function Elastic(map:Map, start:Point, end:Point) {
                        this.map = map;
                        editableLayer = map.editableLayer;
-                       \7f_start = start;
+                       _start = start;
                        _end = end;
                        redraw();
                }
index dfb64490bd6409503d633d4a786ce3f47b584750..644b39f47c53f3c922ead6905e825bae7cfb6645 100644 (file)
@@ -52,7 +52,7 @@ 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(negativeID, 0, tags, true, lat, lon);
+                       var node:Node = new Node(this, negativeID, 0, tags, true, lat, lon);
                        nodes[negativeID]=node; negativeID--;
                        return node;
                }
@@ -62,7 +62,7 @@ package net.systemeD.halcyon {
         * @param nodes An array of Node objects
         */
                public function createWay(tags:Object,nodes:Array):Way {
-                       var way:Way = new Way(negativeID, 0, tags, true, nodes.concat());
+                       var way:Way = new Way(this, negativeID, 0, tags, true, nodes.concat());
                        ways[negativeID]=way; negativeID--;
                        return way;
                }
@@ -72,7 +72,7 @@ package net.systemeD.halcyon {
         * @param members An array of RelationMember objects
         */
                public function createRelation(tags:Object,members:Array):Relation {
-            var relation:Relation = new Relation(negativeID, 0, tags, true, members.concat());
+            var relation:Relation = new Relation(this, negativeID, 0, tags, true, members.concat());
                        relations[negativeID]=relation; negativeID--;
             return relation;
                }
@@ -93,7 +93,7 @@ package net.systemeD.halcyon {
             }
             var marker:Marker = markers[id];
             if (marker == null) {
-              marker = new Marker(id, 0, tags, true, lat, lon);
+              marker = new Marker(this, id, 0, tags, true, lat, lon);
               markers[id]=marker;
             }
             return marker;
index c47ec6d18dc4540a2fd3627e4dfd6e0e1e39911b..3a21b00477a310a3f2f19ae49b5cedae9973ad66 100644 (file)
@@ -107,7 +107,7 @@ package net.systemeD.halcyon.connection {
                     var lat:Number = Number(p[2]);
                     var lon:Number = Number(p[1]);
                     var tags:Object = p[3];
-                    node = new Node(id, version, tags, true, lat, lon);
+                    node = new Node(this, id, version, tags, true, lat, lon);
                     setNode(node,true);
                 }
                 registerPOI(node);
@@ -152,7 +152,7 @@ package net.systemeD.halcyon.connection {
                 var node:Node = getNode(nodeID);
                 if ( node == null ) {
                     var nodeTags:Object = p[3];
-                    node = new Node(nodeID, nodeVersion, nodeTags, true, lat, lon);
+                    node = new Node(this, nodeID, nodeVersion, nodeTags, true, lat, lon);
                 } else if (!node.loaded) {
                                        node.update(nodeVersion, nodeTags, true, false, lat, lon);
                                }
@@ -161,7 +161,7 @@ package net.systemeD.halcyon.connection {
                        }
 
                        if (way==null) {
-               way = new Way(id, version, tags, true, nodes);
+               way = new Way(this, id, version, tags, true, nodes);
                        } else {
                                way.update(version, tags, true, true, nodes);
                        }
@@ -199,21 +199,21 @@ package net.systemeD.halcyon.connection {
                                switch (type) {
                                        case 'Node':
                                                e=getNode(memid);
-                                               if (e==null) { e=new Node(memid,0,{},false,0,0); setNode(Node(e),true); }
+                                               if (e==null) { e=new Node(this, memid,0,{},false,0,0); setNode(Node(e),true); }
                                                break;
                                        case 'Way':
                                                e=getWay(memid);
-                                               if (e==null) { e=new Way(memid,0,{},false,[]); setWay(Way(e),true); }
+                                               if (e==null) { e=new Way(this, memid,0,{},false,[]); setWay(Way(e),true); }
                                                break;
                                        case 'Relation':
                                                e=getRelation(memid);
-                                               if (e==null) { e=new Relation(memid,0,{},false,[]); setRelation(Relation(e),true); }
+                                               if (e==null) { e=new Relation(this, memid,0,{},false,[]); setRelation(Relation(e),true); }
                                                break;
                                }
                                members.push(new RelationMember(e,role));
                        }
                        if (relation==null) {
-                   relation = new Relation(id, version, tags, true, members);
+                   relation = new Relation(this, id, version, tags, true, members);
                        } else {
                                relation.update(version,tags,true,false,members);
                        }
index 096651d0c69dd8e88452a1e97122ae2757bff391..bb1a2bf1ec9d5e786d1ffbe13f0efaa72bb9ca86 100644 (file)
@@ -3,8 +3,8 @@ package net.systemeD.halcyon.connection {
     public class Changeset extends Entity {
                public static var entity_type:String = 'changeset';
 
-        public function Changeset(id:Number, tags:Object) {
-            super(id, 0, tags, true, NaN, '');
+        public function Changeset(connection:Connection, id:Number, tags:Object) {
+            super(connection, id, 0, tags, true, NaN, '');
         }
 
         public override function toString():String {
index 36933f9f4304a5b2fcde19f704d9f40ed67d8491..dced4d3af285f73877fb1f775b7f1a34238c3a25 100644 (file)
@@ -15,7 +15,8 @@ package net.systemeD.halcyon.connection {
         protected var policyURL:String;
         protected var params:Object;
 
-               public function Connection(cname:String,api:String,policy:String,initparams:Object={}) {
+               public function Connection(cname:String,api:String,policy:String,initparams:Object=null) {
+                       initparams = (initparams!=null ? initparams:{});
                        name=cname;
                        apiBaseURL=api;
                        policyURL=policy;
@@ -255,19 +256,19 @@ package net.systemeD.halcyon.connection {
                }
 
         public function createNode(tags:Object, lat:Number, lon:Number, performCreate:Function):Node {
-            var node:Node = new Node(nextNegative, 0, tags, true, lat, lon);
+            var node:Node = new Node(this, nextNegative, 0, tags, true, lat, lon);
             performCreate(new CreateEntityAction(node, setNode));
             return node;
         }
 
         public function createWay(tags:Object, nodes:Array, performCreate:Function):Way {
-            var way:Way = new Way(nextNegative, 0, tags, true, nodes.concat());
+            var way:Way = new Way(this, nextNegative, 0, tags, true, nodes.concat());
             performCreate(new CreateEntityAction(way, setWay));
             return way;
         }
 
         public function createRelation(tags:Object, members:Array, performCreate:Function):Relation {
-            var relation:Relation = new Relation(nextNegative, 0, tags, true, members.concat());
+            var relation:Relation = new Relation(this, nextNegative, 0, tags, true, members.concat());
             performCreate(new CreateEntityAction(relation, setRelation));
             return relation;
         }
index 6a24481f18fc0bae7290e4e2b14e5770883ca59f..fc297f8a45e359faabeb9f279315168f86a5720a 100644 (file)
@@ -8,6 +8,7 @@ package net.systemeD.halcyon.connection {
     /** An Entity is an object stored in the map database, and therefore uploaded and downloaded. This includes Nodes, Ways, 
     *   Relations but also Changesets etc. */
     public class Entity extends EventDispatcher {
+               private var _connection:Connection;
         private var _id:Number;
         private var _version:uint;
         private var _uid:Number;
@@ -22,7 +23,8 @@ package net.systemeD.halcyon.connection {
         /** Have all its parents (ie, relations that contain this object as a member, ways that contain this node) been loaded into memory */
         public var parentsLoaded:Boolean = true;
 
-        public function Entity(id:Number, version:uint, tags:Object, loaded:Boolean, uid:Number, timestamp:String) {
+        public function Entity(connection:Connection, id:Number, version:uint, tags:Object, loaded:Boolean, uid:Number, timestamp:String) {
+                       this._connection = connection;
             this._id = id;
             this._version = version;
             this._uid = uid;
@@ -62,6 +64,11 @@ package net.systemeD.halcyon.connection {
             return _timestamp;
         }
 
+               /** Connection to which this entity belongs. */
+               public function get connection():Connection {
+                       return _connection;
+               }
+
         /** Set a bunch of properties in one hit. Implicitly makes entity not deleted. */
         public function updateEntityProperties(version:uint, tags:Object, loaded:Boolean, parentsLoaded:Boolean, uid:Number, timestamp:String):void {
             _version=version; this.tags=tags; _loaded=loaded; this.parentsLoaded=parentsLoaded; _uid = uid; _timestamp = timestamp;
index 6056cc6c1bbbe4619e2ac6d54d729bbd1227ce6e..ad7f6b85df90570867ac6788ba05e49b4fce1643 100644 (file)
@@ -18,7 +18,10 @@ package net.systemeD.halcyon.connection {
                private var delayedEvents:Array = [];
 
         public function EntityCollection(entities:Array) {
-                       super(-1, 0, {}, true, -1, "");
+                       var conn:Connection=entities[0].connection;
+                       // ** FIXME: this really is a very nasty way of finding the connection
+                       
+                       super(conn, -1, 0, {}, true, -1, "");
             _entities = entities;
                        
                        //To avoid firing on every contained entity, we wait some short time before firing the events
index 0180bfb4e2a598283f414e9757d85cba5dac5849..e39c5c9fee1a352bde56f1afb7e26175ecdf04b3 100644 (file)
@@ -10,8 +10,8 @@ package net.systemeD.halcyon.connection {
         private var _latproj:Number;
         private var _lon:Number;
 
-        public function Marker(id:Number, version:uint, tags:Object, loaded:Boolean, lat:Number, lon:Number) {
-            super(id, version, tags, loaded, 0, null);
+        public function Marker(connection:Connection, id:Number, version:uint, tags:Object, loaded:Boolean, lat:Number, lon:Number) {
+            super(connection, id, version, tags, loaded, 0, null);
             this._lat = lat;
             this._latproj = lat2latp(lat);
             this._lon = lon;
index e185d3f4a26690a6163a5acf54ed93a032e97861..cd3d52696d1446f570038dcc014dff66b0590252 100644 (file)
@@ -7,8 +7,8 @@ package net.systemeD.halcyon.connection {
         private var _latproj:Number;
         private var _lon:Number;
 
-        public function Node(id:Number, version:uint, tags:Object, loaded:Boolean, lat:Number, lon:Number, uid:Number = NaN, timestamp:String = null) {
-            super(id, version, tags, loaded, uid, timestamp);
+        public function Node(connection:Connection, id:Number, version:uint, tags:Object, loaded:Boolean, lat:Number, lon:Number, uid:Number = NaN, timestamp:String = null) {
+            super(connection, id, version, tags, loaded, uid, timestamp);
             this._lat = lat;
             this._latproj = lat2latp(lat);
             this._lon = lon;
index 795dd7810cd8486c01ff0f648c30859cf9dff141..56808d417867c0422c655564ab1d59b283a03709 100644 (file)
@@ -6,8 +6,8 @@ package net.systemeD.halcyon.connection {
         private var members:Array;
                public static var entity_type:String = 'relation';
 
-        public function Relation(id:Number, version:uint, tags:Object, loaded:Boolean, members:Array, uid:Number = NaN, timestamp:String = null) {
-            super(id, version, tags, loaded, uid, timestamp);
+        public function Relation(connection:Connection, id:Number, version:uint, tags:Object, loaded:Boolean, members:Array, uid:Number = NaN, timestamp:String = null) {
+            super(connection, id, version, tags, loaded, uid, timestamp);
             this.members = members;
                        for each (var member:RelationMember in members)
                            member.entity.addParent(this);
index 87ed4e5ddf51234b676fdc5e54060f740b517674..8cefcf1ad2ca6f17285e44bbcd9907f2d80837be 100644 (file)
@@ -11,8 +11,8 @@ package net.systemeD.halcyon.connection {
                private var edge_b:Number;
                public static var entity_type:String = 'way';
 
-        public function Way(id:Number, version:uint, tags:Object, loaded:Boolean, nodes:Array, uid:Number = NaN, timestamp:String = null) {
-            super(id, version, tags, loaded, uid, timestamp);
+        public function Way(connection:Connection, id:Number, version:uint, tags:Object, loaded:Boolean, nodes:Array, uid:Number = NaN, timestamp:String = null) {
+            super(connection, id, version, tags, loaded, uid, timestamp);
             this.nodes = nodes;
                        for each (var node:Node in nodes) { node.addParent(this); }
                        calculateBbox();
index 7d083b5e6019a6876b3bff905552040b40474194..19e0032d3a698383bf7e450bf7becedbcaf212f5 100644 (file)
@@ -54,7 +54,7 @@ package net.systemeD.halcyon.connection {
                         if ( type == "node" ) {
                             member = getNode(memberID);
                             if ( member == null ) {
-                                member = new Node(memberID,0,{},false,0,0);
+                                member = new Node(this,memberID,0,{},false,0,0);
                                 setNode(Node(member),true);
                             } else if (member.isDeleted()) {
                                 member.setDeletedState(false);
@@ -62,13 +62,13 @@ package net.systemeD.halcyon.connection {
                         } else if ( type == "way" ) {
                             member = getWay(memberID);
                             if (member == null) {
-                                member = new Way(memberID,0,{},false,[]);
+                                member = new Way(this,memberID,0,{},false,[]);
                                 setWay(Way(member),true);
                             }
                         } else if ( type == "relation" ) {
                             member = getRelation(memberID);
                             if (member == null) {
-                                member = new Relation(memberID,0,{},false,[]);
+                                member = new Relation(this,memberID,0,{},false,[]);
                                 setRelation(Relation(member),true);
                             }
                         }
@@ -78,7 +78,7 @@ package net.systemeD.halcyon.connection {
                     }
                     
                     if ( rel == null )
-                        setRelation(new Relation(id, version, tags, true, members, uid, timestamp), false);
+                        setRelation(new Relation(this, id, version, tags, true, members, uid, timestamp), false);
                     else {
                         rel.update(version, tags, true, false, members, uid, timestamp);
                         sendEvent(new EntityEvent(NEW_RELATION, rel), false);
@@ -89,7 +89,8 @@ package net.systemeD.halcyon.connection {
             for each(var nodeData:XML in map.node) {
                                id = Number(nodeData.@id);
                                node = getNode(id);
-                               newNode = new Node(id, 
+                               newNode = new Node(this,
+                                                  id, 
                                                   uint(nodeData.@version), 
                                                   parseTags(nodeData.tag),
                                                   true, 
@@ -130,7 +131,7 @@ package net.systemeD.halcyon.connection {
                                        }
                     tags = parseTags(data.tag);
                     if ( way == null ) {
-                        setWay(new Way(id, version, tags, true, nodes, uid, timestamp),false);
+                        setWay(new Way(this, id, version, tags, true, nodes, uid, timestamp),false);
                     } else {
                                                waycount++;
                         way.update(version, tags, true, true, nodes, uid, timestamp);
index 3ce5505997a41062731bbf0beafe15cf4e8e7517..12c6c4a9bd18254f073d718ab3b30574069ee64c 100644 (file)
@@ -142,7 +142,7 @@ package net.systemeD.halcyon.connection {
             var id:Number = Number(URLLoader(event.target).data);
             
             // which means we now have a new changeset!
-            setActiveChangeset(new Changeset(id, lastUploadedChangesetTags));
+            setActiveChangeset(new Changeset(this, id, lastUploadedChangesetTags));
         }
 
         private function changesetCreateError(event:IOErrorEvent):void {