• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jumpinjackie / mapguide-react-layout / 15165370206

21 May 2025 02:48PM UTC coverage: 22.447%. Remained the same
15165370206

push

github

jumpinjackie
#1555: More internalization of things that shouldn't be in the API documentation.

Also dd merge-modules plugin for typedoc which flattens our public symbol list, which makes better sense as our node module usage story is to import from a flat barrel "mapguide-react-layout" module.

878 of 1206 branches covered (72.8%)

4975 of 22163 relevant lines covered (22.45%)

6.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/api/expr-eval-context.ts
1
import Feature from "ol/Feature";
1✔
2
import Geometry from 'ol/geom/Geometry';
3
import { Expression, Parser } from 'expr-eval';
×
4
import { strReplaceAll } from '../utils/string';
×
5
import { isClusteredFeature } from './ol-style-helpers';
×
6

7
/**
8
 * @hidden
9
 */
10
export class ExprEvalContext {
×
11
    private exprCache: {
12
        [expr: string]: Expression;
13
    };
14
    private filterCache: {
15
        [expr: string]: Expression;
16
    };
17
    private clusterExprCache: {
18
        [expr: string]: Expression;
19
    };
20
    private clusterFilterCache: {
21
        [expr: string]: Expression;
22
    };
23
    private parser: Parser;
24
    constructor() {
×
25
        this.exprCache = {};
×
26
        this.filterCache = {};
×
27
        this.clusterExprCache = {};
×
28
        this.clusterFilterCache = {};
×
29
        this.parser = new Parser();
×
30
        this.parser.functions.agg_sum = function (collectionProperty: any, property: string) {
×
31
            if (Array.isArray(collectionProperty)) {
×
32
                const res = collectionProperty.reduce((running, currentItem) => running + (currentItem.get(property) ?? 0), 0);
×
33
                return res;
×
34
            }
×
35
            return undefined;
×
36
        };
×
37
        this.parser.functions.arr_size = function(collectionProperty: any) {
×
38
            if (Array.isArray(collectionProperty)) {
×
39
                return collectionProperty.length;
×
40
            }
×
41
            return 1;
×
42
        };
×
43
        this.parser.functions.feat_property = function(feature: any, name: string) {
×
44
            if (feature) {
×
45
                return feature.get(name);
×
46
            } else {
×
47
                return undefined;
×
48
            }
×
49
        }
×
50
    }
×
51
    public addFilter(expr: string) {
×
52
        if (!this.filterCache[expr]) {
×
53
            this.filterCache[expr] = this.parser.parse(expr);
×
54
        }
×
55
    }
×
56
    public addExpr(expr: string) {
×
57
        if (!this.exprCache[expr]) {
×
58
            this.exprCache[expr] = this.parser.parse(expr);
×
59
        }
×
60
    }
×
61
    public addClusterFilter(expr: string) {
×
62
        if (!this.clusterFilterCache[expr]) {
×
63
            this.clusterFilterCache[expr] = this.parser.parse(expr);
×
64
        }
×
65
    }
×
66
    public addClusterExpr(expr: string) {
×
67
        if (!this.clusterExprCache[expr]) {
×
68
            this.clusterExprCache[expr] = this.parser.parse(expr);
×
69
        }
×
70
    }
×
71
    private cleanValues(feat: Feature<Geometry>) {
×
72
        const vals = feat.getProperties();
×
73
        //UGLY: We have no guarantee that the properties in question will not have
74
        //spaces in them (that will break evaluation), so force the matter by replacing
75
        //spaces with underscores. What this means is if we find a property named "OFFICE TYPE", it
76
        //will be converted to "OFFICE_TYPE"
77
        const keys = Object.keys(vals);
×
78
        const cvals: any = {};
×
79
        for (const k of keys) {
×
80
            cvals[strReplaceAll(k, " ", "_")] = vals[k];
×
81
        }
×
82
        return cvals;
×
83
    }
×
84
    public evaluateFilter(feat: Feature<Geometry>): string | undefined {
×
85
        const cvals = this.cleanValues(feat);
×
86
        const cache = isClusteredFeature(feat) ? this.clusterFilterCache : this.filterCache;
×
87
        for (const filter in cache) {
×
88
            // Does this feature match an expression?
89
            if (cache[filter].evaluate(cvals) == true) {
×
90
                return filter;
×
91
            }
×
92
        }
×
93
        return undefined;
×
94
    }
×
95
    public evaluate(expr: string, feat: Feature<Geometry>): any {
×
96
        const cvals = this.cleanValues(feat);
×
97
        if (isClusteredFeature(feat)) {
×
98
            this.addClusterExpr(expr);
×
99
            return this.clusterExprCache[expr].evaluate(cvals);
×
100
        }
×
101
        else {
×
102
            this.addExpr(expr);
×
103
            return this.exprCache[expr].evaluate(cvals);
×
104
        }
×
105
    }
×
106
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc