do the 'Add to route' button in the route editor
authorRichard Fairhurst <richard@systemed.net>
Fri, 11 Jun 2010 08:27:29 +0000 (08:27 +0000)
committerRichard Fairhurst <richard@systemed.net>
Fri, 11 Jun 2010 08:27:29 +0000 (08:27 +0000)
TODO.txt
net/systemeD/halcyon/connection/Connection.as
net/systemeD/potlatch2/RelationSelectPanel.mxml
net/systemeD/potlatch2/TagViewer.mxml
net/systemeD/potlatch2/mapfeatures/editors/RouteEditor.mxml

index 8108df3..2372995 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -29,7 +29,7 @@ Potlatch 2: main outstanding issues
 == Tag editing ==
 
 ** Doesn't always update selected tab when you select a new entity
-** 'Add to route' in relations doesn't work
+** Doesn't update selected tab when you change the relations on an entity
 ** Direct click-to-edit of relation role should actually work
 * Dynamic reloading of stylesheet/map_features, so that you don't need to reload the full page when editing them
 * If a select name is too long then, the select menu seems to give a horizontal scrollbar instead of the name of the item e.g. cuisine#Coffee Shop
index c4b5818..09f18f9 100755 (executable)
@@ -264,6 +264,19 @@ package net.systemeD.halcyon.connection {
             return list;
         }
 
+        public function getMatchingRelationIDs(match:Object):Array {
+            var list:Array = [];
+                       var ok:Boolean;
+            for each (var relation:Relation in relations) {
+                               ok=true;
+                               for (var k:String in match) {
+                                       if (!relation.getTagsHash()[k] || relation.getTagsHash()[k]!=match[k]) { ok=false; }
+                               }
+                               if (ok) { list.push(relation.id); }
+                       }
+            return list;
+        }
+
                public function getObjectsByBbox(left:Number, right:Number, top:Number, bottom:Number):Object {
                        var o:Object = { poisInside: [], poisOutside: [], waysInside: [], waysOutside: [] };
                        for each (var way:Way in ways) {
index 66b78b6..0f7301f 100644 (file)
         private var conn:Connection;
         private var relationList:Array;
         private var entity:Entity;
+               private var tags:Object;
 
-        public function init(e:Entity):void {
+        public function init(e:Entity, t:Object):void {
           entity = e;
+                 tags = t;
           PopUpManager.addPopUp(this, Application(Application.application), true);
           PopUpManager.centerPopUp(this);
     
           var titles:Array = [];
           conn = Connection.getConnectionInstance();
-          relationList = conn.getAllRelationIDs();
+          relationList = conn.getMatchingRelationIDs(tags);
           if (relationList.length == 0) {
-            warning.text = "No relations loaded";
+            warning.text = "No relations available";
           } else {
             warning.text = "These relations are available:";
           }
@@ -44,7 +46,7 @@
         }
         
         public function closeAndNewRelation():void {
-          var relation:Relation = conn.createRelation({}, [new RelationMember(entity, '')],
+          var relation:Relation = conn.createRelation(tags, [new RelationMember(entity, '')],
               MainUndoStack.getGlobalStack().addAction)
           PopUpManager.removePopUp(this);
           trace("edit relation "+id);
index b18143f..f0b8b8d 100644 (file)
       }
       
       public function addToRelation():void {
-          new RelationSelectPanel().init(selectedEntity);        
+          new RelationSelectPanel().init(selectedEntity,new Object());
       }
       
       public function removeFromRelation(id:Number, index:int):void {
index 33e308b..6ab87fc 100644 (file)
@@ -10,7 +10,7 @@
 
   <mx:Label text="{fieldName}:"/>
   <mx:VBox verticalGap="0" width="100%" id="routeIcons"/>
-  <mx:LinkButton label="Add to route"/>
+  <mx:LinkButton label="Add to route" click="addToRelation()" />
 
   <mx:Script><![CDATA[
     import net.systemeD.halcyon.connection.*;
         panel.setRelation(relation["relation"]);
         PopUpManager.centerPopUp(panel);
     }
+
+      public function addToRelation():void {
+          new RelationSelectPanel().init(_entity, _factory.relationTags);        
+      }
+      
     
   ]]></mx:Script>
 </edit:RelationMemberEditor>