Fix =no MapCSS check. This must be the longest-standing bug in P2...
[potlatch2.git] / net / systemeD / halcyon / styleparser / Rule.as
index 9d210d7277fe8926ee9fb7e9ca6294a1cfc26395..1a1d53adeb7d160b7085c69a7ac64f06ee9b9ec7 100644 (file)
@@ -2,20 +2,37 @@ package net.systemeD.halcyon.styleparser {
 
     import net.systemeD.halcyon.connection.*;
 
+       /**     A MapCSS selector. Contains a list of Conditions; the entity type to which the selector applies; 
+               and the zoom levels at which it is true. way[waterway=river][boat=yes] would be parsed into one Rule. <p>
+               
+               The selectors and declaration together form a StyleChooser.                                                                                       </p>
+               
+               @see net.systemeD.halcyon.styleparser.Condition
+               @see net.systemeD.halcyon.styleparser.StyleChooser */
+
        public class Rule {
 
+               /** The Conditions to be evaluated for the Rule to be fulfilled. */
                public var conditions:Array = [];
+               /** Do all Conditions need to be true for the Rule to be fulfilled? (Always =true for MapCSS.) */
                public var isAnd:Boolean = true;
-               public var minZoom:uint = 13;                   // ** FIXME: shouldn't be hardcoded
-               public var maxZoom:uint = 19;                   //  |
-               public var subject:String='';                   // "", "way", "node" or "relation"
+               /** Minimum zoom level at which the Rule is fulfilled. */
+               public var minZoom:uint = 0;
+               /** Maximum zoom level at which the Rule is fulfilled. */
+               public var maxZoom:uint = 255;
+               /** Entity type to which the Rule applies. Can be 'way', 'node', 'relation', 'area' (closed way) or 'line' (unclosed way). */
+               public var subject:String='';
                
-               public function Rule(s:String=''):void {
-                       subject=s;
+               public function Rule(subject:String=''):void {
+                       this.subject=subject;
                }
                
-               public function test(obj:Entity,tags:Object):Boolean {
-                       if (subject!='' && obj.getType()!=subject) { return false; }
+               /** Evaluate the Rule on the given entity, tags and zoom level.
+                       @return True if the Rule passes, false if the conditions aren't fulfilled. */
+
+               public function test(entity:Entity,tags:Object,zoom:uint):Boolean {
+                       if (subject!='' && !entity.isType(subject)) { return false; }
+                       if (zoom<minZoom || zoom>maxZoom) { return false; }
                        
                        var v:Boolean=true; var i:uint=0;
                        for each (var condition:Condition in conditions) {
@@ -27,7 +44,7 @@ package net.systemeD.halcyon.styleparser {
                        }
                        return v;
                }
-               
+
                public function toString():String {
                        return subject+" z"+minZoom+"-"+maxZoom+": "+conditions;
                }