@@ -9,7 +9,9 @@ var assert = require('assert'),
9
9
// }
10
10
//
11
11
// The selector can have filters
12
- tree . Definition = function Definition ( selector , rules ) {
12
+ tree . Definition = function Definition ( selector , rules , env ) {
13
+ var that = this ;
14
+
13
15
this . elements = selector . elements ;
14
16
assert . ok ( selector . filters instanceof tree . Filterset ) ;
15
17
this . rules = rules ;
@@ -19,10 +21,42 @@ tree.Definition = function Definition(selector, rules) {
19
21
this . rules [ i ] . zoom = selector . zoom ;
20
22
this . ruleIndex [ this . rules [ i ] . updateID ( ) ] = true ;
21
23
}
24
+
22
25
this . filters = selector . filters ;
26
+ if ( this . filters ) {
27
+ if ( _ . isArray ( this . filters ) ) {
28
+ _ . forEach ( this . filters , function ( f ) {
29
+ if ( typeof f . setRule === 'function' ) {
30
+ f . setRule ( that ) ;
31
+ }
32
+ } ) ;
33
+ }
34
+ else {
35
+ if ( typeof this . filters . setRule === 'function' ) {
36
+ this . filters . setRule ( that ) ;
37
+ }
38
+ }
39
+ }
40
+
23
41
this . zoom = selector . zoom ;
42
+
43
+ if ( this . zoom ) {
44
+ if ( _ . isArray ( this . zoom ) ) {
45
+ _ . forEach ( this . zoom , function ( f ) {
46
+ if ( typeof f . setRule === 'function' ) {
47
+ f . setRule ( that ) ;
48
+ }
49
+ } ) ;
50
+ }
51
+ else {
52
+ if ( typeof this . zoom . setRule === 'function' ) {
53
+ this . zoom . setRule ( that ) ;
54
+ }
55
+ }
56
+ }
57
+
24
58
this . attachment = selector . attachment || '__default__' ;
25
- this . specificity = selector . specificity ( ) ;
59
+ this . specificity = selector . specificity ( env ) ;
26
60
this . matchCount = 0 ;
27
61
28
62
// special handling for Map selector
@@ -47,17 +81,34 @@ tree.Definition.prototype.clone = function(filters) {
47
81
clone . ruleIndex = _ . clone ( this . ruleIndex ) ;
48
82
clone . filters = filters ? filters : this . filters . clone ( ) ;
49
83
clone . attachment = this . attachment ;
84
+ clone . matchCount = this . matchCount ;
85
+ clone . specificity = this . specificity ;
86
+ clone . zoom = this . zoom ;
50
87
return clone ;
51
88
} ;
52
89
53
90
tree . Definition . prototype . addRules = function ( rules ) {
54
- var added = 0 ;
91
+ var added = 0 ,
92
+ parent = null ;
93
+
94
+ if ( this . rules . length && this . rules [ 0 ] ) {
95
+ parent = this . rules [ 0 ] . parent ;
96
+ }
55
97
56
98
// Add only unique rules.
57
99
for ( var i = 0 ; i < rules . length ; i ++ ) {
58
- if ( ! this . ruleIndex [ rules [ i ] . id ] ) {
59
- this . rules . push ( rules [ i ] ) ;
60
- this . ruleIndex [ rules [ i ] . id ] = true ;
100
+ var rule = rules [ i ] . clone ( ) ;
101
+ rule . parent = parent ;
102
+ // match rule to definition zoom level
103
+ // if rule zoom less specific than definition zoom
104
+ if ( this . zoom && rule . zoom > this . zoom ) {
105
+ rule . zoom = this . zoom ;
106
+ rule . updateID ( ) ;
107
+ }
108
+
109
+ if ( ! this . ruleIndex [ rule . id ] ) {
110
+ this . rules . push ( rule ) ;
111
+ this . ruleIndex [ rule . id ] = true ;
61
112
added ++ ;
62
113
}
63
114
}
@@ -224,9 +275,9 @@ tree.Definition.prototype.collectSymbolizers = function(zooms, i) {
224
275
}
225
276
} ;
226
277
227
- // The tree.Zoom.toString function ignores the holes in zoom ranges and outputs
278
+ // The tree.Zoom.toObject function ignores the holes in zoom ranges and outputs
228
279
// scaledenominators that cover the whole range from the first to last bit set.
229
- // This algorithm can produces zoom ranges that may have holes. However,
280
+ // This algorithm can produce zoom ranges that may have holes. However,
230
281
// when using the filter-mode="first", more specific zoom filters will always
231
282
// end up before broader ranges. The filter-mode will pick those first before
232
283
// resorting to the zoom range with the hole and stop processing further rules.
0 commit comments