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

geosolutions-it / MapStore2 / 16371927321

18 Jul 2025 01:35PM UTC coverage: 76.895% (-0.03%) from 76.924%
16371927321

Pull #11331

github

web-flow
Merge 52e841647 into e75d26e98
Pull Request #11331: Fix #11103 Update cesium to latest stable 1.131.0 , reviewed all the cesium layers and cesium map.

31259 of 48656 branches covered (64.24%)

33 of 43 new or added lines in 8 files covered. (76.74%)

27 existing lines in 6 files now uncovered.

38805 of 50465 relevant lines covered (76.89%)

36.52 hits per line

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

83.5
/web/client/components/map/cesium/plugins/OverlayLayer.js
1
/**
2
 * Copyright 2015, GeoSolutions Sas.
3
 * All rights reserved.
4
 *
5
 * This source code is licensed under the BSD-style license found in the
6
 * LICENSE file in the root directory of this source tree.
7
 */
8

9
import Layers from '../../../../utils/cesium/Layers';
10
import * as Cesium from 'cesium';
11

12
import eventListener from 'eventlistener';
13
import isEqual from 'lodash/isEqual';
14
/**
15
 * Created by thomas on 27/01/14.
16
 */
17

18
const InfoWindow = (function() {
1✔
19
    function _(cesiumWidget) {
20

21
        this._scene = cesiumWidget.scene;
3✔
22

23
        let div = document.createElement('div');
3✔
24
        div.className = 'infoWindow';
3✔
25
        this._div = div;
3✔
26
        let frame = document.createElement('div');
3✔
27
        frame.className = 'frame';
3✔
28
        this._div.appendChild(frame);
3✔
29
        let content = document.createElement('div');
3✔
30
        content.className = 'content';
3✔
31
        frame.appendChild(content);
3✔
32
        cesiumWidget.container.appendChild(div);
3✔
33
        this._content = content;
3✔
34
        this.setVisible(true);
3✔
35

36
        // set the position to absolute to correctly positioning the info window
37
        // based on left and top properties
38
        this._div.style.position = 'absolute';
3✔
39
    }
40

41
    _.prototype.setVisible = function(visible) {
1✔
42
        this._visible = visible;
12✔
43
        this._div.style.display = visible ? 'block' : 'none';
12!
44
    };
45

46
    _.prototype.setContent = function(content) {
1✔
47
        if (typeof content === 'string') {
3!
48
            this._content.innerHTML = content;
×
49
        } else {
50
            while (this._content.firstChild) {
3✔
51
                this._content.removeChild(this._content.firstChild);
×
52
            }
53
            this._content.appendChild(content);
3✔
54
        }
55
    };
56

57
    _.prototype.setPosition = function(lat, lng) {
1✔
58
        this._position = this._scene.globe.ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(lng, lat, 0));
3✔
59
    };
60

61
    _.prototype.showAt = function(lat, lng, content) {
1✔
62
        this.setPosition(lat, lng);
3✔
63
        this.setContent(content);
3✔
64
        this.setVisible(true);
3✔
65
    };
66

67
    _.prototype.hide = function() {
1✔
68
        this.setVisible(false);
×
69
    };
70

71
    _.prototype.computeVisible = function() {
1✔
72
        // Ellipsoid radii - WGS84 shown here
73
        const rX = 6378137.0;
3✔
74
        const rY = 6378137.0;
3✔
75
        const rZ = 6356752.3142451793;
3✔
76
        // Vector CV
77
        const cameraPosition = this._scene.camera.position;
3✔
78
        const cvX = cameraPosition.x / rX;
3✔
79
        const cvY = cameraPosition.y / rY;
3✔
80
        const cvZ = cameraPosition.z / rZ;
3✔
81

82
        const vhMagnitudeSquared = cvX * cvX + cvY * cvY + cvZ * cvZ - 1.0;
3✔
83

84
        // Target position, transformed to scaled space
85

86
        const position = this._position;
3✔
87
        const tX = position.x / rX;
3✔
88
        const tY = position.y / rY;
3✔
89
        const tZ = position.z / rZ;
3✔
90

91
        // Vector VT
92
        const vtX = tX - cvX;
3✔
93
        const vtY = tY - cvY;
3✔
94
        const vtZ = tZ - cvZ;
3✔
95
        const vtMagnitudeSquared = vtX * vtX + vtY * vtY + vtZ * vtZ;
3✔
96

97
        // VT dot VC is the inverse of VT dot CV
98
        const vtDotVc = -(vtX * cvX + vtY * cvY + vtZ * cvZ);
3✔
99

100
        const isOccluded = vtDotVc > vhMagnitudeSquared &&
3!
101
            vtDotVc * vtDotVc / vtMagnitudeSquared > vhMagnitudeSquared;
102

103
        if (isOccluded) {
3!
104
            this.setVisible(false);
×
105
        } else {
106
            this.setVisible(true);
3✔
107
        }
108

109
    };
110

111
    _.prototype.update = function() {
1✔
112
        this.computeVisible();
3✔
113

114
        if (!this._visible || !this._position) {
3!
115
            return;
×
116
        }
117
        // get the position on the globe as screen coordinates
118
        // coordinates with origin at the top left corner
119
        let coordinates = Cesium.SceneTransforms.wgs84ToWindowCoordinates(this._scene, this._position);
3✔
UNCOV
120
        if (coordinates) {
×
UNCOV
121
            let left = Math.floor(coordinates.x) - this._div.clientWidth / 2 + "px";
×
UNCOV
122
            let top = Math.floor(coordinates.y) - this._div.clientHeight + "px";
×
UNCOV
123
            this._div.tabIndex = 5;
×
UNCOV
124
            this._div.style.left = left;
×
UNCOV
125
            this._div.style.top = top;
×
126
        }
127
    };
128

129
    _.prototype.destroy = function() {
1✔
130
        this._div.parentNode.removeChild(this._div);
×
131
    };
132

133
    return _;
1✔
134

135
})();
136

137
const removeIds = (items) => {
1✔
138
    if (items.length !== 0) {
5✔
139
        for (let i = 0; i < items.length; i++) {
2✔
140
            let item = items.item(i);
2✔
141
            item.removeAttribute('data-reactid');
2✔
142
            removeIds(item.children || []);
2!
143
        }
144
    }
145
};
146

147
const cloneOriginalOverlay = (original, options) => {
1✔
148
    let cloned = original.cloneNode(true);
3✔
149
    cloned.id = options.id + '-overlay';
3✔
150
    cloned.className = (options.className || original.className) + "-overlay";
3✔
151
    cloned.removeAttribute('data-reactid');
3✔
152
    // remove reactjs generated ids from cloned object
153
    removeIds(cloned.children || []);
3!
154
    // handle optional close button on overlay
155
    const closeClassName = options.closeClass || 'close';
3✔
156
    if (options.onClose && cloned.getElementsByClassName(closeClassName).length === 1) {
3✔
157
        const close = cloned.getElementsByClassName(closeClassName)[0];
1✔
158
        const onClose = (e) => {
1✔
159
            options.onClose(e.target.getAttribute('data-overlayid'));
1✔
160
        };
161
        eventListener.add(close, 'click', onClose);
1✔
162
    }
163
    return cloned;
3✔
164
};
165

166
Layers.registerType('overlay', {
1✔
167
    create: (options, map) => {
168

169
        if (!options.visibility) {
3!
170
            return {
×
171
                detached: true,
172
                info: undefined,
173
                remove: () => {}
174
            };
175
        }
176
        const original = document.getElementById(options.id);
3✔
177
        // use a div fallback to avoid error if the original element does not exist
178
        const cloned = original ? cloneOriginalOverlay(original, options) : document.createElement('div');
3!
179

180
        let infoWindow = new InfoWindow(map);
3✔
181
        infoWindow.showAt(options?.position?.y || 0, options?.position?.x || 0, cloned);
3!
182
        infoWindow.setVisible(true);
3✔
183

184
        // Make infoWindow compatible with Cesium Primitive interface
185
        infoWindow.isDestroyed = function() {
3✔
186
            return false;
3✔
187
        };
188

189
        let info = map.scene.primitives.add(infoWindow);
3✔
190

191
        return {
3✔
192
            detached: true,
193
            info: info,
194
            remove: () => {
195
                map.scene.primitives.remove(info);
×
196
            }
197
        };
198
    },
199
    update: function(layer, newOptions, oldOptions, map) {
200
        if (!isEqual(newOptions.position, oldOptions.position)) {
×
201
            return this.create(newOptions, map);
×
202
        }
203
        return null;
×
204
    }
205
});
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