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

jumpinjackie / mapguide-react-layout / 15160422871

21 May 2025 11:00AM UTC coverage: 21.479% (-42.8%) from 64.24%
15160422871

Pull #1552

github

web-flow
Merge 3916e4b02 into 236e2ea07
Pull Request #1552: Feature/package updates 2505

840 of 1168 branches covered (71.92%)

11 of 151 new or added lines in 25 files covered. (7.28%)

1332 existing lines in 50 files now uncovered.

4794 of 22319 relevant lines covered (21.48%)

6.84 hits per line

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

58.27
/src/api/composite-selection.ts
1
import { ICompositeSelectionLayer, ICompositeSelection, Bounds } from "./common";
2
import { ClientSelectionLayer, ClientSelectionSet } from "./contracts/common";
3
import { SelectedFeature, SelectedLayer, FeatureProperty, SelectedFeatureSet } from "./contracts/query";
4

5
//FIXME: We are inlining extend of ol/Extent here so that this module can be included in any jest test case
6
//without jest complaining about not being able to import ol's ES6 modules. I don't know how to get jest to
7
//recognize ol imports. None of the solutions I tried worked!
UNCOV
8
function extend(extent1: Bounds, extent2: Bounds) {
×
9
    if (extent2[0] < extent1[0]) {
×
10
        extent1[0] = extent2[0];
×
UNCOV
11
    }
×
12
    if (extent2[2] > extent1[2]) {
×
13
        extent1[2] = extent2[2];
×
UNCOV
14
    }
×
15
    if (extent2[1] < extent1[1]) {
×
16
        extent1[1] = extent2[1];
×
UNCOV
17
    }
×
18
    if (extent2[3] > extent1[3]) {
×
19
        extent1[3] = extent2[3];
×
UNCOV
20
    }
×
21
    return extent1;
×
UNCOV
22
}
×
23

24
/**
25
 * A layer of a {@link CompositeSelection}
26
 * 
27
 * @since 0.14
28
 */
29
export class CompositeSelectionLayer implements ICompositeSelectionLayer {
1✔
30
    private features: SelectedFeature[];
31
    constructor(private layer: SelectedLayer | ClientSelectionLayer) {
1✔
32
        this.features = [];
12✔
33
        if (this.isSelectedLayer(this.layer)) {
12✔
34
            for (const f of this.layer.Feature) {
10✔
35
                this.features.push(f);
20✔
36
            }
20✔
37
        } else {
12✔
38
            for (const f of this.layer.features) {
2✔
39
                const fp = [] as FeatureProperty[];
2✔
40
                for (const k in f.properties) {
2✔
41
                    fp.push({
4✔
42
                        Name: k,
4✔
43
                        Value: f.properties[k]
4✔
44
                    })
4✔
45
                }
4✔
46
                const fb = f.bounds ? f.bounds.join(" ") : undefined;
2!
47
                this.features.push({
2✔
48
                    Bounds: fb,
2✔
49
                    Property: fp
2✔
50
                });
2✔
51
            }
2✔
52
        }
2✔
53
    }
12✔
54
    private isSelectedLayer(layer: SelectedLayer | ClientSelectionLayer): layer is SelectedLayer {
1✔
55
        return (layer as any).Feature
94✔
56
            && (layer as any)["@id"]
78✔
57
            && (layer as any)["@name"]
78✔
58
    }
94✔
59
    /**
60
     * Gets the combined bounds of all selected features
61
     * 
62
     * @returns The combined bounds of all selected features in the projection of the current map view
63
     */
64
    public getBounds(): Bounds | undefined {
1✔
UNCOV
65
        let bounds: Bounds | undefined;
×
66
        if (this.isSelectedLayer(this.layer)) {
×
67
            this.layer.Feature.forEach(feat => {
×
68
                const b: Bounds | undefined = feat.Bounds
×
69
                    ? (feat.Bounds.split(" ").map(s => parseFloat(s)) as Bounds)
×
UNCOV
70
                    : undefined;
×
71
                if (b) {
×
72
                    if (!bounds) {
×
73
                        bounds = b;
×
UNCOV
74
                    } else {
×
75
                        bounds = extend(bounds, b) as Bounds;
×
UNCOV
76
                    }
×
UNCOV
77
                }
×
UNCOV
78
            });
×
UNCOV
79
        } else {
×
80
            for (const f of this.layer.features) {
×
81
                if (f.bounds) {
×
82
                    if (bounds == null) {
×
83
                        bounds = f.bounds;
×
UNCOV
84
                    } else {
×
85
                        bounds = extend(bounds, f.bounds) as Bounds;
×
UNCOV
86
                    }
×
UNCOV
87
                }
×
UNCOV
88
            }
×
UNCOV
89
        }
×
90
        return bounds;
×
UNCOV
91
    }
×
92
    public getLayerId() {
1✔
93
        if (this.isSelectedLayer(this.layer)) {
37✔
94
            return this.layer["@id"];
31✔
95
        }
31✔
96
        return undefined;
6✔
97
    }
37✔
98
    public getName() {
1✔
99
        if (this.isSelectedLayer(this.layer)) {
34✔
100
            return this.layer["@name"];
28✔
101
        } else {
34✔
102
            return this.layer.name;
6✔
103
        }
6✔
104
    }
34✔
105
    public getFeatureAt(featureIndex: number) {
1✔
106
        return this.features[featureIndex];
27✔
107
    }
27✔
108
    public getFeatureCount() { return this.features.length; }
1✔
109
    public getLayerMetadata() {
1✔
110
        if (this.isSelectedLayer(this.layer)) {
11✔
111
            return this.layer.LayerMetadata;
9✔
112
        }
9✔
113
        return undefined;
2✔
114
    }
11✔
115
}
1✔
116

117
/**
118
 * A composition of a MapGuide selection set and a client-side vector feature selection
119
 * 
120
 * @since 0.14
121
 */
122
export class CompositeSelection implements ICompositeSelection {
1✔
123
    private layers: CompositeSelectionLayer[];
124
    constructor(mgSelection?: SelectedFeatureSet, clientSelection?: ClientSelectionSet) {
1✔
125
        this.layers = [];
10✔
126
        if (mgSelection) {
10✔
127
            for (const layer of mgSelection.SelectedLayer) {
7✔
128
                this.layers.push(new CompositeSelectionLayer(layer));
10✔
129
            }
10✔
130
        }
7✔
131
        if (clientSelection) {
10✔
132
            for (const layer of clientSelection.layers) {
2✔
133
                this.layers.push(new CompositeSelectionLayer(layer));
2✔
134
            }
2✔
135
        }
2✔
136
    }
10✔
137
    public getBounds(): Bounds | undefined {
1✔
138
        if (this.layers.length == 0) {
×
139
            return undefined;
×
UNCOV
140
        }
×
UNCOV
141
        let bounds: Bounds | undefined;
×
142
        for (const lyr of this.layers) {
×
143
            let layerBounds = lyr.getBounds();
×
144
            if (layerBounds) {
×
145
                if (bounds) {
×
146
                    bounds = extend(bounds, layerBounds) as Bounds;
×
UNCOV
147
                } else {
×
148
                    bounds = layerBounds;
×
UNCOV
149
                }
×
UNCOV
150
            }
×
UNCOV
151
        }
×
152
        return bounds;
×
UNCOV
153
    }
×
154
    public getLayers() { return this.layers; }
1✔
155
    public getLayerCount() {
1✔
156
        return this.layers.length;
41✔
157
    }
41✔
158
    public getLayerAt(layerIndex: number) {
1✔
159
        return this.layers[layerIndex];
56✔
160
    }
56✔
161
    public getFeatureAt(layerIndex: number, featureIndex: number) {
1✔
162
        const layer = this.getLayerAt(layerIndex);
22✔
163
        return layer?.getFeatureAt(featureIndex);
22✔
164
    }
22✔
165
}
1✔
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