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 52fa42c715483db9513110f6daaaf4bf9ffad45e..69fdbf34dcfc48e3c9791dfc9360e6c74f97dcbe 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 ab2a04f8df215025fa0a53ef62b8e24b0948c70f..5fc43f4a6ff6f09a79daa20136912c27929adaf9 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 38fa3523aa4f1791a32aad8117e6fa9b4701a31b..e34a8cde0a07fec5612a62defc234ac60f4e0470 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 714d9c34f6333e0ca18e04972a252a7d20bcb658..39b46d00170f8467e3fa5b5d8d61e09067b2139a 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 e3a00a7180b0226335466fe9069cc580e7cc1fe2..92d72ea0312d3be8ecc0d06852584ae77cf7113d 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 )