relations now fire events on member addition/removal, and both WayUI and TagViewer...
authorDave Stubbs <osm@randomjunk.co.uk>
Sun, 28 Feb 2010 17:08:24 +0000 (17:08 +0000)
committerDave Stubbs <osm@randomjunk.co.uk>
Sun, 28 Feb 2010 17:08:24 +0000 (17:08 +0000)
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/connection/Relation.as
net/systemeD/halcyon/connection/RelationMemberEvent.as [new file with mode: 0644]
net/systemeD/potlatch2/TagViewer.mxml
resources/features/restriction__no_left.png [new file with mode: 0644]
resources/features/restriction__no_right.png [new file with mode: 0644]
resources/potlatch.css

index 0b1a27a..533acb1 100755 (executable)
@@ -33,7 +33,10 @@ package net.systemeD.halcyon {
             way.addEventListener(Connection.WAY_NODE_ADDED, wayNodeAdded);
             way.addEventListener(Connection.WAY_NODE_REMOVED, wayNodeRemoved);
                        way.addEventListener(Connection.WAY_DELETED, wayDeleted);
+                       way.addEventListener(Connection.ADDED_TO_RELATION, wayRelationAdded);
+                       way.addEventListener(Connection.REMOVED_FROM_RELATION, wayRelationRemoved);
             attachNodeListeners();
+            attachRelationListeners();
                }
                
                private function attachNodeListeners():void {
@@ -41,6 +44,23 @@ package net.systemeD.halcyon {
                 way.getNode(i).addEventListener(Connection.NODE_MOVED, nodeMoved);
             }
                }
+
+               private function attachRelationListeners():void {
+                   var relations:Array = way.parentRelations;
+            for each(var relation:Relation in relations ) {
+                relation.addEventListener(Connection.TAG_CHANGE, relationTagChanged);
+            }
+               }
+               
+               private function wayRelationAdded(event:RelationMemberEvent):void {
+                   event.relation.addEventListener(Connection.TAG_CHANGE, relationTagChanged);
+                   redraw();
+               }
+               
+               private function wayRelationRemoved(event:RelationMemberEvent):void {
+                   event.relation.removeEventListener(Connection.TAG_CHANGE, relationTagChanged);
+                   redraw();
+               }
                
                private function wayNodeAdded(event:WayNodeEvent):void {
                    event.node.addEventListener(Connection.NODE_MOVED, nodeMoved);
@@ -55,6 +75,9 @@ package net.systemeD.halcyon {
         private function wayTagChanged(event:TagEvent):void {
             redraw();
         }
+        private function relationTagChanged(event:TagEvent):void {
+            redraw();
+        }
         private function nodeMoved(event:NodeMovedEvent):void {
             redraw();
         }
index af65f7b..fa11a69 100755 (executable)
@@ -66,6 +66,10 @@ package net.systemeD.halcyon.connection {
                public static var NODE_DELETED:String = "node_deleted";
                public static var WAY_DELETED:String = "way_deleted";
                public static var RELATION_DELETED:String = "relation_deleted";
+               public static var RELATION_MEMBER_ADDED:String = "relation_member_added";
+               public static var RELATION_MEMBER_REMOVED:String = "relation_member_deleted";
+               public static var ADDED_TO_RELATION:String = "added_to_relation";
+               public static var REMOVED_FROM_RELATION:String = "removed_from_relation";
 
         // store the data we download
         private var negativeID:Number = -1;
index 66f0ff0..3f1db95 100644 (file)
@@ -135,10 +135,16 @@ package net.systemeD.halcyon.connection {
                
                public function addParent(parent:Entity):void {
                        parents[parent]=true;
+                       
+                       if ( parent is Relation )
+                           dispatchEvent(new RelationMemberEvent(Connection.ADDED_TO_RELATION, this, parent as Relation, -1));
                }
 
                public function removeParent(parent:Entity):void {
                        delete parents[parent];
+
+                       if ( parent is Relation )
+                           dispatchEvent(new RelationMemberEvent(Connection.REMOVED_FROM_RELATION, this, parent as Relation, -1));
                }
                
                public function get parentWays():Array {
index 59524d0..a9743b9 100644 (file)
@@ -7,14 +7,19 @@ package net.systemeD.halcyon.connection {
         public function Relation(id:Number, version:uint, tags:Object, loaded:Boolean, members:Array) {
             super(id, version, tags, loaded);
             this.members = members;
-                       for each (var member:RelationMember in members) { member.entity.addParent(this); }
+                       for each (var member:RelationMember in members)
+                           member.entity.addParent(this);
         }
 
         public function update(version:uint, tags:Object, loaded:Boolean, members:Array):void {
                        var member:RelationMember;
-                       for each (member in this.members) { member.entity.removeParent(this); }
-                       updateEntityProperties(version,tags,loaded); this.members=members;
-                       for each (member in members) { member.entity.addParent(this); }
+                       for each (member in this.members)
+                           member.entity.removeParent(this);
+
+                       updateEntityProperties(version,tags,loaded);
+                       this.members=members;
+                       for each (member in members)
+                           member.entity.addParent(this);
                }
                
         public function get length():uint {
@@ -46,40 +51,54 @@ package net.systemeD.halcyon.connection {
 
         public function setMember(index:uint, member:RelationMember):void {
             var oldMember:RelationMember = getMember(index);
-            oldMember.entity.removeParent(this);
             
-                       member.entity.addParent(this);
                        members.splice(index, 1, member);
+            oldMember.entity.removeParent(this);
+                       member.entity.addParent(this);
                        markDirty();
         }
 
         public function insertMember(index:uint, member:RelationMember):void {
-                       member.entity.addParent(this);
             members.splice(index, 0, member);
+                       member.entity.addParent(this);
                        markDirty();
+                       
+                       dispatchEvent(new RelationMemberEvent(Connection.RELATION_MEMBER_ADDED, member.entity, this, index));
         }
 
         public function appendMember(member:RelationMember):uint {
-                       member.entity.addParent(this);
             members.push(member);
+                       member.entity.addParent(this);
                        markDirty();
+
+                       dispatchEvent(new RelationMemberEvent(Connection.RELATION_MEMBER_ADDED, member.entity, this, members.length-1));
             return members.length;
         }
 
                public function removeMember(entity:Entity):void {
                        var i:int;
+                       var lastRemoved:int = -1;
                        while ((i=findEntityMemberIndex(entity))>-1) {
                                members.splice(i, 1);
+                               lastRemoved = i;
                        }
                        entity.removeParent(this);
                        markDirty();
+                       
+                       if ( lastRemoved >= 0 )
+                           dispatchEvent(new RelationMemberEvent(Connection.RELATION_MEMBER_REMOVED, entity, this, lastRemoved));
                }
 
         public function removeMemberByIndex(index:uint):void {
             var removed:Array=members.splice(index, 1);
                        var entity:Entity=removed[0].entity;
-                       if (findEntityMemberIndex(entity)==-1) { entity.removeParent(this); }
+                       
+                       // only remove as parent if this was only reference
+                       if (findEntityMemberIndex(entity)==-1)
+                           entity.removeParent(this);
+                           
                        markDirty();
+            dispatchEvent(new RelationMemberEvent(Connection.RELATION_MEMBER_REMOVED, entity, this, index));
         }
 
                public override function remove():void {
diff --git a/net/systemeD/halcyon/connection/RelationMemberEvent.as b/net/systemeD/halcyon/connection/RelationMemberEvent.as
new file mode 100644 (file)
index 0000000..84f214b
--- /dev/null
@@ -0,0 +1,25 @@
+package net.systemeD.halcyon.connection {
+
+    import flash.events.Event;
+
+    public class RelationMemberEvent extends EntityEvent {
+        private var _relation:Relation;
+        private var _index:int;
+
+        public function RelationMemberEvent(type:String, member:Entity, relation:Relation, index:int) {
+            super(type, member);
+            this._relation = relation;
+            this._index = index;
+        }
+
+        public function get relation():Relation { return _relation; }
+        public function get member():Entity { return entity; }
+        public function get index():uint { return _index; }
+
+        public override function toString():String {
+            return super.toString() + " in "+_relation+" at "+_index;
+        }
+    }
+
+}
+
index 483b9a2..fe2278d 100644 (file)
              setupAdvanced(selectedEntity);
       }
 
+      private var listeningToRelations:Array = [];
+      
       private function setupAdvanced(entity:Entity):void {
           if ( tagDataProvider == null ) {
               tagDataProvider = new ArrayCollection();
               for each(var tag:Tag in tags)
                   tagDataProvider.addItem(tag);
           }
+                    
+          removeRelationListeners();
+          if ( selectedEntity != null ) {
+              selectedEntity.removeEventListener(Connection.ADDED_TO_RELATION, addedToRelation);
+              selectedEntity.removeEventListener(Connection.REMOVED_FROM_RELATION, removedFromRelation);
+          }
           
           if ( entity == null ) {
               relationsGrid.dataProvider = null;
           } else {
-              var relations:Array = [];
-              for each( var rel:Relation in entity.parentRelations ) {
-                  for each( var memberIndex:int in rel.findEntityMemberIndexes(entity)) {
-                    var props:Object = {};
-                    props["relation"] = rel;
-                    props["id"] = rel.id;
-                    props["index"] = memberIndex;
-                    props["role"] = rel.getMember(memberIndex).role;
-                    props["description"] = rel.getDescription();
-                    props["id_idx"] = rel.id + "/"+memberIndex;
-                    
-                    relations.push(props);
-                  }
+              resetRelationsGrid(entity);
+              entity.addEventListener(Connection.ADDED_TO_RELATION, addedToRelation);
+              entity.addEventListener(Connection.REMOVED_FROM_RELATION, removedFromRelation);
+          }
+      }
+      
+      private function addedToRelation(event:RelationMemberEvent):void {
+         resetRelationsGrid(selectedEntity);
+      }
+
+      private function removedFromRelation(event:RelationMemberEvent):void {
+         resetRelationsGrid(selectedEntity);
+      }
+
+      private function removeRelationListeners():void {
+          for each( var rel:Relation in listeningToRelations ) {
+              rel.removeEventListener(Connection.TAG_CHANGE, relationTagChanged);
+              rel.removeEventListener(Connection.RELATION_MEMBER_ADDED, entityRelationMemberChanged);
+              rel.removeEventListener(Connection.RELATION_MEMBER_REMOVED, entityRelationMemberChanged);
+          }
+          listeningToRelations = [];
+      }
+            
+      private function resetRelationsGrid(entity:Entity):void {
+          removeRelationListeners();
+          var relations:Array = [];
+          for each( var rel:Relation in entity.parentRelations ) {
+              for each( var memberIndex:int in rel.findEntityMemberIndexes(entity)) {
+                  var props:Object = {};
+                  props["relation"] = rel;
+                  props["id"] = rel.id;
+                  props["index"] = memberIndex;
+                  props["role"] = rel.getMember(memberIndex).role;
+                  props["description"] = rel.getDescription();
+                  props["id_idx"] = rel.id + "/"+memberIndex;
+
+                  relations.push(props);
               }
-              relationsGrid.dataProvider = relations;
+              
+              rel.addEventListener(Connection.TAG_CHANGE, relationTagChanged);
+              rel.addEventListener(Connection.RELATION_MEMBER_ADDED, entityRelationMemberChanged);
+              rel.addEventListener(Connection.RELATION_MEMBER_REMOVED, entityRelationMemberChanged);
+              listeningToRelations.push(rel);
           }
+          relationsGrid.dataProvider = relations;
+      }
+      
+      private function relationTagChanged(event:TagEvent):void {
+          resetRelationsGrid(selectedEntity);
+      }
+
+      private function entityRelationMemberChanged(event:RelationMemberEvent):void {
+          resetRelationsGrid(selectedEntity);
       }
       
       private function checkMembers():void {
diff --git a/resources/features/restriction__no_left.png b/resources/features/restriction__no_left.png
new file mode 100644 (file)
index 0000000..9d16952
Binary files /dev/null and b/resources/features/restriction__no_left.png differ
diff --git a/resources/features/restriction__no_right.png b/resources/features/restriction__no_right.png
new file mode 100644 (file)
index 0000000..1cd51f0
Binary files /dev/null and b/resources/features/restriction__no_right.png differ
index 5270308..d2cc999 100644 (file)
@@ -127,4 +127,9 @@ node :junction :selectedway { z-index: 8; icon-image: square; icon-width: 12; ca
    which is part of a relation whose type=route". */
 
 relation[type=route] way { z-index: 1; width: 17; color: blue; opacity: 0.3; }
+relation[type=route][route=bicycle][network=ncn] way { z-index: 1; width: 12; color: red; opacity: 0.3; }
+relation[type=route][route=bicycle][network=rcn] way { z-index: 1; width: 12; color: cyan; opacity: 0.3; }
+relation[type=route][route=bicycle][network=lcn] way { z-index: 1; width: 12; color: blue; opacity: 0.3; }
+relation[type=route][route=foot] way { z-index: 1; width: 10; color: #80ff80; opacity: 0.6; }
+