5
5
Filters can be used to change which features in a layer are rendered. Filters can be
6
6
applied to a layer by the ` setLayerFilters ` method on the Felt controller.
7
7
8
+ Filters use a tree structure for combining expressions with logical operators, called a
9
+ [ FilterTernary] ( FilterTernary.md ) . When combining three or more conditions, you must use proper nesting
10
+ rather than a flat list.
11
+
12
+ See the examples below for the correct structure to use when building complex filters.
13
+
8
14
# Remarks
9
15
10
16
The possible operators are:
@@ -26,15 +32,80 @@ The allowed boolean operators are:
26
32
# Example
27
33
28
34
``` typescript
29
- // a simple filter
35
+ // 1. Simple filter: single condition
30
36
felt .setLayerFilters ({
31
37
layerId: " layer-1" ,
32
38
filters: [" AREA" , " gt" , 30_000 ],
33
39
});
34
40
35
- // compound filters can be constructed using boolean logic:
41
+ // 2. Basic compound filter: two conditions with AND
42
+ felt .setLayerFilters ({
43
+ layerId: " layer-1" ,
44
+ filters: [
45
+ [" AREA" , " gt" , 30_000 ], // First condition
46
+ " and" , // Logic operator
47
+ [" COLOR" , " eq" , " red" ] // Second condition
48
+ ]
49
+ });
50
+
51
+ // 3. Complex filter: three or more conditions require nesting
52
+ // ⚠️ IMPORTANT: Filters use a tree structure, not a flat list
36
53
felt .setLayerFilters ({
37
54
layerId: " layer-1" ,
38
- filters: [[" AREA" , " gt" , 30_000 ], " and" , [" COLOR" , " eq" , " red" ]]
39
- })
55
+ filters: [
56
+ [" AREA" , " gt" , 30_000 ], // First condition
57
+ " and" , // First logic operator
58
+ [ // Nested group starts
59
+ [" COLOR" , " eq" , " red" ], // Second condition
60
+ " and" , // Second logic operator
61
+ [" TYPE" , " eq" , " residential" ] // Third condition
62
+ ] // Nested group ends
63
+ ]
64
+ });
65
+
66
+ // 4. Even more complex: four conditions with proper nesting
67
+ // Visual structure:
68
+ // AND
69
+ // / \
70
+ // condition AND
71
+ // / \
72
+ // condition AND
73
+ // / \
74
+ // condition condition
75
+ felt .setLayerFilters ({
76
+ layerId: " layer-1" ,
77
+ filters: [
78
+ [" AREA" , " gt" , 30_000 ], // First condition
79
+ " and" ,
80
+ [
81
+ [" COLOR" , " eq" , " red" ], // Second condition
82
+ " and" ,
83
+ [
84
+ [" TYPE" , " eq" , " residential" ], // Third condition
85
+ " and" ,
86
+ [" YEAR" , " gt" , 2000 ] // Fourth condition
87
+ ]
88
+ ]
89
+ ]
90
+ });
91
+
92
+ // 5. Mixed operators: combining AND and OR
93
+ // Visual structure:
94
+ // AND
95
+ // / \
96
+ // condition OR
97
+ // / \
98
+ // condition condition
99
+ felt .setLayerFilters ({
100
+ layerId: " layer-1" ,
101
+ filters: [
102
+ [" AREA" , " gt" , 30_000 ], // Must have large area
103
+ " and" ,
104
+ [
105
+ [" COLOR" , " eq" , " red" ], // Must be either red
106
+ " or" ,
107
+ [" TYPE" , " eq" , " residential" ] // OR residential type
108
+ ]
109
+ ]
110
+ });
40
111
```
0 commit comments