-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgeoStringAttributeFilter.ts
More file actions
67 lines (58 loc) · 2.16 KB
/
geoStringAttributeFilter.ts
File metadata and controls
67 lines (58 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { GeoFilter } from "./geoFilter";
import { GeoFilterItem } from "./geoFilterItem";
export class GeoStringAttributeFilter extends GeoFilter {
expectedValues: string[];
expectedValueIndexs: number[];
constructor(filterItems: GeoFilterItem[]) {
super(filterItems);
}
initializeCore() {
let expectedValue = this.filterItems[0].value;
expectedValue = expectedValue.slice(1, expectedValue.length - 1);
this.expectedValues = expectedValue.split(",");
this.key = this.filterItems[0].key;
}
matchFeatureCore(feature: any, zoom: number): boolean {
let currentValue;
let currentExpectedValues;
if (this.replacedValueToIndex) {
currentValue = feature.propertiesIndex[this.keyIndex];
currentExpectedValues = this.expectedValueIndexs;
}
else {
if (feature.properties !== undefined) {
currentValue = feature.properties[this.key];
}
else {
currentValue = feature.get(this.key)
}
// currentValue = feature.properties[this.key];
currentExpectedValues = this.expectedValues;
}
switch (this.filterItems[0].operator) {
case "=":
return currentExpectedValues.includes(currentValue);
case "!=":
default:
return !currentExpectedValues.includes(currentValue);
}
}
replaceVaulesToPbfIndexCore(pbfLayer) {
if (!this.initialized) {
this.initialize();
}
this.keyIndex = pbfLayer.keys.indexOf(this.key);
let replacedExpectedVaules = [];
for (let j = 0, jj = this.expectedValues.length; j < jj; j++) {
let numberValue = +this.expectedValues[j];
if (isNaN(numberValue)) {
replacedExpectedVaules.push(pbfLayer.values.indexOf(this.expectedValues[j]));
}
else {
replacedExpectedVaules.push(pbfLayer.values.indexOf(numberValue));
}
}
this.expectedValueIndexs = replacedExpectedVaules;
this.replacedValueToIndex = true;
}
}