how do I hate thee, Flex? let me count the ways
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / MapFeatures.as
index e3a00a7180b0226335466fe9069cc580e7cc1fe2..13428df1b01ee906f465280166f7db1f636f23f5 100644 (file)
@@ -63,15 +63,26 @@ package net.systemeD.potlatch2.mapfeatures {
                 return null;
 
             for each(var feature:Feature in features) {
-                // check for matching tags
                 var match:Boolean = true;
+
+                // check for matching tags
                 for each(var tag:Object in feature.tags) {
                     var entityTag:String = entity.getTag(tag.k);
                     match = entityTag == tag.v || (entityTag != null && tag.v == "*");
                     if ( !match ) break;
                 }
-                if ( match )
+
+                               // check for matching withins
+                               if (match) {
+                                       for each (var within:Object in feature.withins) {
+                                               match = entity.countParentObjects(within) >= (within.minimum ? within.minimum : 1);
+                                               if (!match) { break; }
+                                       }
+                               }
+
+                if (match) {
                     return feature;
+                               }
             }
             return null;
         }
@@ -79,10 +90,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 )
@@ -90,6 +116,19 @@ package net.systemeD.potlatch2.mapfeatures {
             return _features;
         }
 
+        [Bindable(event="featuresLoaded")]
+        public function get pois():Array {
+            if (xml == null )
+                return null;
+            var pois:Array = [];
+            var counter:int = 0;
+            for each ( var feature:Feature in _features ) {
+              if (feature.isType("point")) {
+                pois.push(feature);
+              }
+            }
+            return pois;
+        }
     }
 
 }