filter category selector by element type
authorDave Stubbs <osm@randomjunk.co.uk>
Sat, 9 Jan 2010 16:10:20 +0000 (16:10 +0000)
committerDave Stubbs <osm@randomjunk.co.uk>
Sat, 9 Jan 2010 16:10:20 +0000 (16:10 +0000)
net/systemeD/potlatch2/CategorySelector.mxml
net/systemeD/potlatch2/TagViewer.mxml
net/systemeD/potlatch2/mapfeatures/Category.as
net/systemeD/potlatch2/mapfeatures/Feature.as
net/systemeD/potlatch2/mapfeatures/MapFeatures.as

index 52fa42c..69fdbf3 100644 (file)
@@ -7,9 +7,9 @@
   <mx:ToggleButtonBar height="100%" dataProvider="{categoryStack}" direction="vertical"/>
   <mx:ViewStack id="categoryStack" width="100%" height="100%"
       creationComplete="setSelectedFeature(_selectedType);">
-      <mx:Repeater id="catRep" dataProvider="{MapFeatures.getInstance().categories}">
+      <mx:Repeater id="catRep" dataProvider="{MapFeatures.getInstance().getCategoriesForType(limit)}">
           <mx:VBox label="{catRep.currentItem.name}">
-          <mx:TileList dataProvider="{catRep.currentItem.features}"
+          <mx:TileList dataProvider="{catRep.currentItem.getFeaturesForType(limit)}"
                        width="100%" height="100%" change="itemSelected(event);"
                        creationComplete="ensureSelection();">
               <mx:itemRenderer>
       
       private var settingSelection:Boolean = false;
       private var _selectedType:Feature;
+      private var _limit:String;
       
       [Bindable(event="selectedType")]
       public function get selectedType():Feature {
           return _selectedType;
       }
       
+      [Bindable(event="limitChanged")]
+      public function get limit():String {
+          return _limit;
+      }
+      
       private function itemSelected(event:Event):void {
           _selectedType = Feature(TileList(event.currentTarget).selectedItem);
           if ( !settingSelection )
               dispatchEvent(new Event("selectedType"));
       }
       
+      public function setLimitTypes(type:String):void {
+          _limit = type;
+          dispatchEvent(new Event("limitChanged"));
+      }
+      
       /**
        * Set the selected feature displayed in the selector.
        *
@@ -69,7 +80,8 @@
               var primaryCategory:Category = feature.findFirstCategory();
           
               // set the tab to the selected item's category
-              categoryStack.selectedIndex = primaryCategory.index;
+              var index:int = MapFeatures.getInstance().getCategoriesForType(limit).indexOf(primaryCategory);
+              categoryStack.selectedIndex = index;
           }
           
           // finalise the item selection
index ab2a04f..5fc43f4 100644 (file)
           var txt:String = feature.htmlDetails(entity);
           iconText.htmlText = txt;
           popupChange.label = feature.name;
+          setLimitTypes(entity);
           tw.setSelectedFeature(feature);
       }
+      
+      private function setLimitTypes(entity:Entity):void {
+          var type:String = null;
+          if ( entity is Node )
+              type = "point";
+          else if ( entity is Way )
+              type = Way(entity).isArea() ? "area" : "line";
+          else if ( entity is Relation )
+              type = "relation";
+          tw.setLimitTypes(type);
+      }
 
       private function blankFeatureIcon(entity:Entity):void {
           iconImage.source = null;
                "<i>Nothing selected</i>" :
                "<b>Not recognised</b><br/>Try looking at the tags under the advanced properties";
           popupChange.label = "unknown";
+          setLimitTypes(entity);
           tw.setSelectedFeature(null);
       }
 
index 38fa352..e34a8cd 100644 (file)
@@ -40,6 +40,20 @@ package net.systemeD.potlatch2.mapfeatures {
         public function get features():Array {
             return _features;
         }
+        
+        [Bindable(event="featuresChanged")]
+        public function getFeaturesForType(type:String):Array {
+            if ( type == null || type == "" )
+                return _features;
+                
+            var filteredFeatures:Array = new Array();
+            for each( var feature:Feature in _features ) {
+                if ( feature.isType(type) )
+                    filteredFeatures.push(feature);
+            }
+            return filteredFeatures;
+        }
+        
     }
 }
 
index 714d9c3..39b46d0 100644 (file)
@@ -137,6 +137,11 @@ package net.systemeD.potlatch2.mapfeatures {
             }
             return null;
         }
+        
+        public function isType(type:String):Boolean {
+            return _xml.elements(type).length() > 0;
+        }
+        
     }
 }
 
index e3a00a7..92d72ea 100644 (file)
@@ -79,10 +79,25 @@ package net.systemeD.potlatch2.mapfeatures {
         [Bindable(event="featuresLoaded")]
         public function get categories():Array {
             if ( xml == null )
-                return null;            
+                return null;        
             return _categories;
         }
 
+        [Bindable(event="featuresLoaded")]
+        public function getCategoriesForType(type:String):Array {
+            if ( xml == null )
+                return null;
+            if ( type == null || type == "" )  
+                return _categories;
+                
+            var filteredCategories:Array = new Array();
+            for each( var cat:Category in _categories ) {
+                if ( cat.getFeaturesForType(type).length > 0 )
+                    filteredCategories.push(cat);
+            }
+            return filteredCategories;
+        }
+
         [Bindable(event="featuresLoaded")]
         public function get features():Array {
             if ( xml == null )