add 'line' and 'area' MapCSS objects
[potlatch2.git] / net / systemeD / halcyon / styleparser / Rule.as
1 package net.systemeD.halcyon.styleparser {
2
3     import net.systemeD.halcyon.connection.*;
4
5         public class Rule {
6
7                 public var conditions:Array = [];
8                 public var isAnd:Boolean = true;
9                 public var minZoom:uint = 0;
10                 public var maxZoom:uint = 255;
11                 public var subject:String='';                   // "", "way", "area", "line", "node" or "relation"
12                 
13                 public function Rule(s:String=''):void {
14                         subject=s;
15                 }
16                 
17                 public function test(obj:Entity,tags:Object,zoom:uint):Boolean {
18                         if (subject!='' && !obj.isType(subject)) { return false; }
19                         if (zoom<minZoom || zoom>maxZoom) { return false; }
20                         
21                         var v:Boolean=true; var i:uint=0;
22                         for each (var condition:Condition in conditions) {
23                                 var r:Boolean=condition.test(tags);
24                                 if (i==0) { v=r; }
25                                 else if (isAnd) { v=v && r; }
26                                 else { v = v || r;}
27                                 i++;
28                         }
29                         return v;
30                 }
31
32                 public function toString():String {
33                         return subject+" z"+minZoom+"-"+maxZoom+": "+conditions;
34                 }
35         }
36 }